示例#1
0
  /** Returns event_id of newly created logging entry. */
  private Integer logEvent(IClient client, String eventText, InputStream logFileSteam, Connection c)
      throws SQLException {
    PreparedStatement stmt = null;
    int id = 0;
    try {
      long longId = getSequenceId("seq_client_log_event_ids", c);
      if (longId > Integer.MAX_VALUE) {
        // dat_client_log_events.event_id is a 32 bit integer numeric type.

        // this is a bad problem; ensure it's logged; don't depend on whoever's catching
        // the exception.
        m_logger.log("seq_client_log_event_ids overflowed").error();
        throw new IllegalStateException("seq_client_log_event_ids overflowed.");
      }
      id = (int) longId;
      stmt =
          c.prepareStatement(
              "insert into dat_client_log_events "
                  + "(event_id, customer_id, user_id, event_time, description, has_log_file) "
                  + "values "
                  + "(?, ?, ?, current_timestamp, ?, ?)");

      stmt.setInt(1, id);
      stmt.setInt(2, client.getCustomerId());
      stmt.setInt(3, client.getUserId());
      stmt.setString(4, eventText);
      stmt.setInt(5, logFileSteam == null ? 0 : 1);
      if (stmt.executeUpdate() != 1) {
        throw new SQLException("Can't insert client event for " + client);
      }
    } finally {
      DbUtils.safeClose(stmt);
    }
    return new Integer(id);
  }
示例#2
0
 @Override
 public synchronized void run() {
   if (isAlive) {
     if (communicator.isRemote()) {
       Log.i("PartyHardyHost", "listening for connections");
       while (true) {
         try {
           Client newClient = new Client(((ServerSocket) communicator.getSocket()).accept());
           Log.i("PartyHardyHost", newClient + " connecting");
           ((IHost) communicator).onClientConnect(newClient);
         } catch (IOException e) {
           e.printStackTrace();
           Log.e("PartyHardyHost", e.getMessage());
           break;
         }
       }
     } else {
       IClient client = (IClient) communicator;
       client.setSender(new Sender((Socket) communicator.getSocket()));
       client.setReceiver(new Receiver(communicator));
       new Thread(client.getSender()).start();
       new Thread(client.getReceiver()).start();
     }
   }
 }
示例#3
0
  public boolean logEvent(
      final IClient client, final String eventText, final InputStream logFileStream) {
    Integer id =
        executeWithConnection(
            new ConnectionExecuteFunction<Integer>() {
              public Integer execute(Connection c) throws SQLException {
                return logEvent(client, eventText, logFileStream, c);
              }
            });

    if (id == null) {
      // DB error would have already been logged.
      return false;
    }

    boolean ok = false;
    if (logFileStream == null) {
      ok = true;
    } else {
      File userMailDir = client.getUserMailbox().getBaseDir();
      File logFile = getEventLogFile(userMailDir, id.intValue());
      try {
        FileUtils.copyStreamToFile(logFileStream, logFile);
        ok = true;
      } catch (IOException ioe) {
        m_logger
            .log("Can't write log file")
            .param(LoggingConsts.USER_ID, client.getUserId())
            .param(LoggingConsts.FILENAME, logFile == null ? "" : logFile.getAbsolutePath())
            .param(LoggingConsts.CONTENT, eventText)
            .error(ioe);
      }
    }
    return ok;
  }
示例#4
0
  /**
   * Update the mail signal file with a current timestamp.
   *
   * @param client
   */
  public void stampNewmailFile(IClient client) {
    if (client == null) {
      return;
    }
    String cachePath = client.getNewMailCachePath();
    File f = new File(getCacheBase(), cachePath);

    // matches scheme used in smtpnotify.py
    long stamp = System.currentTimeMillis() / 5000;
    byte[] content = Long.toString(stamp).getBytes();

    // It's not necessary to write the file atomically.
    // It's not critical information; the worst that can happen is
    // the client does an unnecessary retrieve call into the backend.
    touchFile(f, content, client.getUserId(), false);
  }
  public boolean checkPermissions(IClient client, RequestFunction function, AMFDataList params) {
    boolean doesStreamExist = false;
    boolean authorized = false;

    String streamName;
    try {
      streamName = params.getString(PARAM1).split("\\?")[0];
    } catch (Exception ex) {
      return false;
    }

    IMediaStream stream = client.getAppInstance().getStreams().getStream(streamName);

    getLogger().info("Checking stream Name: " + streamName);

    doesStreamExist = (stream != null);

    if (doesStreamExist) {
      authorized = false;
    } else {
      authorized = true;
    }

    // add other permission checking

    getLogger().info("Authorized: " + authorized);

    return authorized;
  }
示例#6
0
  /**
   * Utility method to create client and load balancer (if enabled in client config) given the name
   * and client config. Instances are created using reflection (see {@link
   * #instantiateInstanceWithClientConfig(String, IClientConfig)}
   *
   * @param restClientName
   * @param clientConfig
   * @throws ClientException if any errors occurs in the process, or if the client with the same
   *     name already exists
   */
  public static synchronized IClient<?, ?> registerClientFromProperties(
      String restClientName, IClientConfig clientConfig) throws ClientException {
    IClient<?, ?> client = null;
    ILoadBalancer loadBalancer = null;
    if (simpleClientMap.get(restClientName) != null) {
      throw new ClientException(
          ClientException.ErrorType.GENERAL,
          "A Rest Client with this name is already registered. Please use a different name");
    }
    try {
      String clientClassName =
          (String) clientConfig.getProperty(CommonClientConfigKey.ClientClassName);
      client = (IClient<?, ?>) instantiateInstanceWithClientConfig(clientClassName, clientConfig);
      boolean initializeNFLoadBalancer =
          Boolean.parseBoolean(
              clientConfig
                  .getProperty(
                      CommonClientConfigKey.InitializeNFLoadBalancer,
                      DefaultClientConfigImpl.DEFAULT_ENABLE_LOADBALANCER)
                  .toString());
      if (initializeNFLoadBalancer) {
        loadBalancer = registerNamedLoadBalancerFromclientConfig(restClientName, clientConfig);
      }
      if (client instanceof AbstractLoadBalancerAwareClient) {
        ((AbstractLoadBalancerAwareClient) client).setLoadBalancer(loadBalancer);
      }
    } catch (Throwable e) {
      String message =
          "Unable to InitializeAndAssociateNFLoadBalancer set for RestClient:" + restClientName;
      logger.warn(message, e);
      throw new ClientException(ClientException.ErrorType.CONFIGURATION, message, e);
    }
    simpleClientMap.put(restClientName, client);

    Monitors.registerObject("Client_" + restClientName, client);

    logger.info("Client Registered:" + client.toString());
    return client;
  }
  public void releaseStream(IClient client, RequestFunction function, AMFDataList params) {
    boolean bAuthorized = false;

    try {
      bAuthorized = checkPermissions(client, function, params);
    } catch (Exception ex) {
      // some error
    }

    if (bAuthorized != true) {
      sendClientOnStatusError(client, "NetStream.Publish.Denied", "Invalid credentials supplied");
      client.setShutdownClient(true);
    } else {
      invokePrevious(client, function, params);
    }
  }
示例#8
0
  public Set<GameObject> getAtLocal(int x, int y, int mask) {
    IClient client = ctx.getClient();
    Set<GameObject> objects = new LinkedHashSet<GameObject>();
    if (client.getScene().getSceneTiles() == null) {
      return objects;
    }

    try {
      int plane = client.getPlane();
      ISceneTile tile = client.getScene().getSceneTiles()[plane][x][y];

      if (tile != null) {

        x += client.getOriginX();
        y += client.getOriginY();

        // Interactable (e.g. Trees)
        if ((mask & TYPE_INTERACTABLE) != 0) {
          for (ISceneObject obj : tile.getInteractableObjects()) {
            if (obj != null) {
              GameObject gameobj =
                  new GameObject(
                      ctx,
                      obj,
                      GameObject.Type.INTERACTABLE,
                      plane,
                      new Tile(x, y, obj.getGridX(), obj.getGridY()));

              if (gameobj.getId() != -1) {
                objects.add(gameobj);
              }
            }
          }
        }

        if ((mask & TYPE_FLOOR_DECORATION) != 0) {
          if (tile.getFloorDecoration() != null) {
            IFloorDecoration dec = tile.getFloorDecoration();

            GameObject gameobj =
                new GameObject(
                    ctx,
                    dec,
                    GameObject.Type.FLOOR_DECORATION,
                    plane,
                    new Tile(x, y, dec.getGridX(), dec.getGridY()));
            if (gameobj.getId() != -1) {
              objects.add(gameobj);
            }
          }
        }

        if ((mask & TYPE_WALL_DECORATION) != 0) {
          if (tile.getWallDecoration() != null) {
            IWallDecoration dec = tile.getWallDecoration();
            GameObject gameobj =
                new GameObject(
                    ctx,
                    dec,
                    GameObject.Type.WALL_DECORATION,
                    plane,
                    new Tile(x, y, dec.getGridX(), dec.getGridY()));

            if (gameobj.getId() != -1) {
              objects.add(gameobj);
            }
          }
        }

        if ((mask & TYPE_BOUNDARY) != 0) {
          if (tile.getBoundary() != null) {
            IWall dec = tile.getBoundary();
            GameObject gameobj =
                new GameObject(
                    ctx,
                    dec,
                    GameObject.Type.BOUNDARY,
                    plane,
                    new Tile(x, y, dec.getGridX(), dec.getGridY()));

            if (gameobj.getId() != -1) {
              objects.add(gameobj);
            }
          }
        }
      }
    } catch (Exception ignored) {
    }
    return objects;
  }