Esempio n. 1
0
  public InetSocketAddress getPortalServer() {
    String server;
    if (iniSettings.isPrivatePortalServerUse())
      server = iniSettings.getPrivatePortalServerAddress();
    else server = portalServerList.next();

    return Utility.parseSocketAddress(server);
  }
Esempio n. 2
0
  public void queryPortalServer(final PortalQuery query) {
    String server;
    if (iniSettings.isPrivatePortalServerUse())
      server = iniSettings.getPrivatePortalServerAddress();
    else server = portalServerList.next();

    if (Utility.isEmpty(server)) {
      query.failCallback(new ErrorLog("ポータルサーバーが設定されていません"));
      return;
    }

    final InetSocketAddress address = Utility.parseSocketAddress(server);

    Runnable task =
        new Runnable() {
          @Override
          public void run() {
            try {
              tcpClient.connect(
                  address,
                  ProtocolConstants.TIMEOUT,
                  new IProtocol() {
                    @Override
                    public void log(String message) {
                      arenaWindow.appendToSystemLog(message, true);
                    }

                    @Override
                    public String getProtocol() {
                      return ProtocolConstants.PROTOCOL_PORTAL;
                    }

                    @Override
                    public IProtocolDriver createDriver(final ISocketConnection connection) {
                      connection.send(Utility.encode(query.getCommand()));

                      return new IProtocolDriver() {
                        private String message;

                        @Override
                        public void errorProtocolNumber(String number) {
                          String error =
                              String.format(
                                  "サーバーとのプロトコルナンバーが一致しないので接続できません サーバー:%s クライアント:%s",
                                  number, IProtocol.NUMBER);
                          arenaWindow.appendToSystemLog(error, true);
                        }

                        @Override
                        public ISocketConnection getConnection() {
                          return connection;
                        }

                        @Override
                        public boolean process(PacketData data) {
                          message = data.getMessage();
                          return false;
                        }

                        @Override
                        public void connectionDisconnected() {
                          if (message != null) query.successCallback(message);
                          else query.failCallback(new ErrorLog("利用可能なサーバーが見つかりません"));
                        }
                      };
                    }
                  });
            } catch (IOException e) {
              query.failCallback(new ErrorLog(e));
            }
          }
        };
    executorService.execute(task);
  }