private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int version = in.readInt();
   caseSensitive = in.readBoolean();
   if (version > 0) markDeletions = in.readBoolean();
   if (version > 1) {
     stoplist = (HashSet<String>) in.readObject();
   }
 }
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();

    isAdapter = in.readBoolean();
    if (isAdapter) {
      if (adapter_readAdapterObject == null) throw new ClassNotFoundException();
      Object[] args = {this, in};
      try {
        javaObject = adapter_readAdapterObject.invoke(null, args);
      } catch (Exception ex) {
        throw new IOException();
      }
    } else {
      javaObject = in.readObject();
    }

    String className = (String) in.readObject();
    if (className != null) {
      staticType = Class.forName(className);
    } else {
      staticType = null;
    }

    initMembers();
  }
Exemplo n.º 3
0
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    prefix = (String) in.readObject();
    int gsl = in.readInt();
    if (gsl > 0) {
      gramSizes = new int[gsl];
      for (int i = 0; i < gsl; i++) gramSizes[i] = in.readInt();
    }

    if (version >= 1) {
      distinguishBorders = in.readBoolean();
    }
  }
Exemplo n.º 4
0
 private void receiveEGTable_EXT() {
   int nBytes = (nBits - 1) / 8 + 1;
   try {
     for (int j = 0; j < nCols; j++) {
       boolean temp = ois.readBoolean();
       if (temp) EGTable[j] = Utils.readBigInteger(nBytes * Wire.labelBitLength, ois);
       else EGTable[j] = null;
     }
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int size1, size2;
   int version = in.readInt();
   size1 = in.readInt();
   ;
   if (size1 == NULL_INTEGER) {
     conjunctions = null;
   } else {
     conjunctions = new int[size1][];
     for (int i = 0; i < size1; i++) {
       size2 = in.readInt();
       if (size2 == NULL_INTEGER) {
         conjunctions[i] = null;
       } else {
         conjunctions[i] = new int[size2];
         for (int j = 0; j < size2; j++) {
           conjunctions[i][j] = in.readInt();
         }
       }
     }
   }
   includeOriginalSingletons = in.readBoolean();
 }
Exemplo n.º 6
0
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == butConnect) {
      try {
        boolean ok = serverConnection();
        if (ok) {
          setInitPanel();
        } else {
          System.out.println("Le pseudo existe déjà, choisissez en un autre.");
        }
      } catch (IOException err) {
        System.err.println(
            "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butListParty) {
      try {
        // envoyer requête LIST PARTY
        oos.writeInt(JungleServer.REQ_LISTPARTY);
        oos.flush();

        // recevoir résultat et l'afficher dans textInfoInit
        System.out.println("flush");
        boolean pret = ois.readBoolean();
        System.out.println(pret);
        if (pret) {
          String nomParty = (String) ois.readObject();
          System.out.println("apres read");
          textInfoInit.append(nomParty + " ");
        }

      } catch (ClassNotFoundException err) {
      } catch (IOException err) {
        System.err.println(
            "Problème de connection avec le serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }

    } else if (e.getSource() == butCreateParty) {
      try {
        boolean ok;
        // envoyer requête CREATE PARTY (paramètres : nom partie et nb joueurs nécessaires)
        oos.writeInt(JungleServer.REQ_CREATEPARTY);
        oos.writeObject(textCreate.getText());
        int nbJoueurs = (Integer) spinNbPlayer.getValue();
        oos.writeInt(nbJoueurs);
        oos.flush();
        // recevoir résultat -> ok
        ok = ois.readBoolean();
        System.out.println(ok);
        // si ok == true :
        if (ok) {
          // mettre le panneau party au centre
          setPartyPanel();
          // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie
          textInfoParty.append("Attendre le début de la partie");
          // créer un ThreadClient et lancer son exécution
          ThreadClient threadClient = new ThreadClient(this);
          threadClient.start();
        }
      } catch (IOException err) {
        System.err.println(
            "probleme de connection serveur : " + err.getMessage() + "\n.Aborting...");
        System.exit(1);
      }
    } else if (e.getSource() == butJoinParty) {

      try {
        int idPlayer;
        // envoyer requête JOIN PARTY (paramètres : numero partie)
        oos.writeInt(JungleServer.REQ_JOINPARTY);
        oos.flush();
        System.out.println("requete envoyée");
        int numPartie = Integer.parseInt(textJoin.getText());
        oos.writeInt(numPartie);
        oos.flush();
        System.out.println("numPartie flushé");
        // recevoir résultat -> idPlayer
        idPlayer = ois.readInt();
        System.out.println("idplayer reçu : " + idPlayer);
        // si idPlayer >= 1 :
        if (idPlayer >= 1) {
          // mettre le panneau party au centre
          setPartyPanel();
          // afficher un message dans textInfoParty comme quoi il faut attendre le début de partie
          textInfoParty.append("Attendre la début de la partie");
          // créer un ThreadClient et lancer son exécution
          System.out.println("avant démarrage du thread");
          ThreadClient threadClient = new ThreadClient(this);
          threadClient.start();
          System.out.println("Apres le thread");
        }
      } catch (IOException err) {
        System.err.println("Problème de connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butPlay) {
      try {
        // envoyer requête PLAY (paramètre : contenu de textPlay)
        oos.writeInt(JungleServer.REQ_PLAY);
        oos.writeObject(textPlay.getText());
        oos.flush();
        orderSent = true;
        butPlay.setEnabled(false);
        textPlay.setEnabled(false);

        // mettre orderSent à true
        // bloquer le bouton play et le textfiled associé
      } catch (IOException err) {
        System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    } else if (e.getSource() == butQuit) {
      try {
        oos.close();
        ois.close();
        setConnectionPanel();
        comm = null;
      } catch (IOException err) {
        System.err.println("Problème connection serveur: " + err.getMessage() + "\n.Arrêt...");
        System.exit(1);
      }
    }
  }
Exemplo n.º 7
0
 private void receiveParams() throws Exception {
   nCols = ois.readInt();
   nCIBits = ois.readInt();
   nBits = ois.readInt();
   extCase = ois.readBoolean();
 }
Exemplo n.º 8
0
 public void run() {
   Server.preRunOperations(this);
   while (true) {
     try {
       String type = in.readUTF();
       if (type.equals("newObject")) {
         Object object = in.readObject();
         if (object instanceof String) {
           // Adding player..
           this.player = new Player((String) object, Entity.BLUE);
           boolean addPlayer = true;
           for (int i = 0; i < Server.players.size(); i++) {
             if (this.player.name.equals(Server.players.get(i).name)) {
               // Set to online!
               if (Server.players.get(i).online) {
                 System.out.println(
                     "Player " + player.name + " is already connected! " + (userID + 1));
                 this.player = null;
                 addPlayer = false;
               } else {
                 this.player = Server.players.get(i);
                 System.out.println("Returning User: "******", " + (userID + 1));
                 this.player.online = true;
                 addPlayer = false;
               }
               break;
             }
           }
           if (addPlayer) {
             System.out.println("New User: "******", " + (userID + 1));
             Server.players.add(this.player);
           }
         }
       } else if (type.equals(
           "MoveUnit")) { // this needs to require the player to be the owner of the unit
         short unit = in.readShort();
         double cX = in.readDouble();
         double cY = in.readDouble();
         double x = in.readDouble();
         double y = in.readDouble();
         boolean stacked = in.readBoolean();
         // Pretty simple: (If the unit doesn't "exist", game will take care of that.) [Keep in
         // mind, this currently could easily let the player control enemy units]
         new PathFind(
             unit, cX, cY, x, y,
             stacked); // All commands take the liberty of adding themselves to the game stack.
       } else if (type.equals(
           "SetTarget")) { // this needs to require the player to be the owner of the unit
         short unit = in.readShort();
         short enemy = in.readShort();
         boolean stacked = in.readBoolean();
         // Pretty simple:
         new SetTarget(unit, enemy, stacked);
       } else if (type.equals("AddOrder")) {
         short unit = in.readShort();
         byte order = in.readByte();
         double atX = in.readDouble();
         double atY = in.readDouble();
         boolean stacked = in.readBoolean();
         new AddOrder(unit, order, atX, atY, stacked);
       } else if (type.equals("Uber")) {
         short unit = in.readShort();
         boolean stacked = in.readBoolean();
         new Uber(unit, stacked);
       } else if (type.equals("Exiting")) {
         disconnect();
         return;
       }
     } catch (IOException e) {
       disconnect();
       return;
     } catch (Exception e) {
       System.out.println("Alternate error.");
       e.printStackTrace();
     }
   }
 }
  /** {@inheritDoc} */
  @SuppressWarnings("ErrorNotRethrown")
  @Override
  public IpcEndpoint accept() throws IgniteCheckedException {
    while (!Thread.currentThread().isInterrupted()) {
      Socket sock = null;

      boolean accepted = false;

      try {
        sock = srvSock.accept();

        accepted = true;

        InputStream inputStream = sock.getInputStream();
        ObjectInputStream in = new ObjectInputStream(inputStream);

        ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());

        IpcSharedMemorySpace inSpace = null;

        IpcSharedMemorySpace outSpace = null;

        boolean err = true;

        try {
          IpcSharedMemoryInitRequest req = (IpcSharedMemoryInitRequest) in.readObject();

          if (log.isDebugEnabled()) log.debug("Processing request: " + req);

          IgnitePair<String> p = inOutToken(req.pid(), size);

          String file1 = p.get1();
          String file2 = p.get2();

          assert file1 != null;
          assert file2 != null;

          // Create tokens.
          new File(file1).createNewFile();
          new File(file2).createNewFile();

          if (log.isDebugEnabled()) log.debug("Created token files: " + p);

          inSpace = new IpcSharedMemorySpace(file1, req.pid(), pid, size, true, log);

          outSpace = new IpcSharedMemorySpace(file2, pid, req.pid(), size, false, log);

          IpcSharedMemoryClientEndpoint ret =
              new IpcSharedMemoryClientEndpoint(inSpace, outSpace, log);

          out.writeObject(
              new IpcSharedMemoryInitResponse(
                  file2, outSpace.sharedMemoryId(), file1, inSpace.sharedMemoryId(), pid, size));

          err = !in.readBoolean();

          endpoints.add(ret);

          return ret;
        } catch (UnsatisfiedLinkError e) {
          throw IpcSharedMemoryUtils.linkError(e);
        } catch (IOException e) {
          if (log.isDebugEnabled())
            log.debug(
                "Failed to process incoming connection "
                    + "(was connection closed by another party):"
                    + e.getMessage());
        } catch (ClassNotFoundException e) {
          U.error(log, "Failed to process incoming connection.", e);
        } catch (ClassCastException e) {
          String msg =
              "Failed to process incoming connection (most probably, shared memory "
                  + "rest endpoint has been configured by mistake).";

          LT.warn(log, null, msg);

          sendErrorResponse(out, e);
        } catch (IpcOutOfSystemResourcesException e) {
          if (!omitOutOfResourcesWarn) LT.warn(log, null, OUT_OF_RESOURCES_MSG);

          sendErrorResponse(out, e);
        } catch (IgniteCheckedException e) {
          LT.error(log, e, "Failed to process incoming shared memory connection.");

          sendErrorResponse(out, e);
        } finally {
          // Exception has been thrown, need to free system resources.
          if (err) {
            if (inSpace != null) inSpace.forceClose();

            // Safety.
            if (outSpace != null) outSpace.forceClose();
          }
        }
      } catch (IOException e) {
        if (!Thread.currentThread().isInterrupted() && !accepted)
          throw new IgniteCheckedException("Failed to accept incoming connection.", e);

        if (!closed)
          LT.error(
              log, null, "Failed to process incoming shared memory connection: " + e.getMessage());
      } finally {
        U.closeQuiet(sock);
      }
    } // while

    throw new IgniteInterruptedCheckedException("Socket accept was interrupted.");
  }