Exemplo n.º 1
1
 /** renders the template and wraps it to a full httpresponse */
 public void renderTemplate(IRequest req) {
   if (tpl == null) {
     if (this.ts == null) ts = Server.srv.templatemanager.getTemplateSet("default");
     tpl = ts.getTemplate(tName);
     if (tpl == null) tpl = ts.getTemplate("not_found");
   }
   if (tpl.isRedirect()) {
     this.setRedirectTo(tpl.getDestination(), req.getCookieDomain());
     return;
   }
   if (!nocache
       && !nostore
       && !tpl.hasToBeRendered(
           req.getProperty("if-none-match"),
           HttpDateParser.parseDate(req.getProperty("if-modified-since")))) {
     StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
     sb.append(IResponseHeaders.NOT_MODIFIED);
     sb.trimToSize();
     prepareForSending(CharBuffer.wrap(sb.toString()));
     return;
   }
   String cntnt = tpl.render(req);
   if (cntnt == null || cntnt.length() < 1) {
     Server.log(
         this,
         "renderTemplate: rendered template has no content",
         Server.MSG_STATE,
         Server.LVL_MAJOR);
     resCode = NOCONTENT_CODE;
     StringBuffer sb = new StringBuffer();
     sb.append("<html><body><b>The requested page could not be displayed!<br><br>Reason:</b> ");
     if (tpl == null) {
       sb.append("No template given");
     } else {
       sb.append("Template '");
       sb.append(tpl.getName());
       sb.append("' has not been found on this server.");
     }
     sb.append("</body></html>");
     wrap(sb.toString(), req.getCookieDomain());
     return;
   }
   nocache = tpl.notCacheable();
   //      if (nocache)
   //          Server.log (this, "not cacheable", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
   wrap(cntnt, tpl.getEtag(), req.getCookieDomain());
 }
Exemplo n.º 2
0
  /**
   * enthaelt den ausfuehrbaren Code des Threads; hier wird auf Nachrichten gewartet, die dann ueber
   * das Server-Objekt weitergeleitet werden koennen (siehe Methode forward() des Servers). Die
   * Zieladresse der Nachricht wird ueberprueft, um dann die Nachricht an die entsprechende
   * Server-Methode weiterzugeben. Im Fehlerfall wird hier die Verbindung getrennt und die Methode
   * shutdown() auf dem Server aufgerufen, um das Spiel zu entfernen.
   *
   * @exception IOException
   * @exception InterruptedIOException
   */
  public void run() {
    while (!isInterrupted()) {
      // hier wird die Zieladresse (target) aus der Nachricht extrahiert
      try {
        String message = receive();
        // System.out.println("ServerThread "+myNumber+":"+" "+message);

        if (message != null) {
          StringTokenizer ST = new StringTokenizer(message);
          int target = Integer.parseInt(ST.nextToken());
          System.out.println("sending message from " + myNumber + " to " + target);
          // falls target="-1": Nachricht an Server; sonst Nachricht
          // an Spieler x
          if (target >= -1) {
            server.forward(gameID, message);
          } else {
            send("1exit");
            server.deletePlayer(message + " " + gameID);
            interrupt();

            try {
              connection.close();
            } catch (IOException ex) {
            }
          }

        } else {
          String log = "Aborting game! Player " + (myNumber + 1) + " has left the game\n";
          System.out.print(log);
          server.log(log, server.getPort());
          interrupt();
          server.shutdown(nameOfTheGame + " " + myNumber + " " + gameID, log);
        }
      } catch (InterruptedIOException e) {
        String log =
            "Aborting game! TimeOut while receiving message"
                + " from player "
                + (myNumber + 1)
                + "\n";
        System.out.print(log);
        server.log(log, server.getPort());
        interrupt();
        server.shutdown(nameOfTheGame + " " + myNumber + " " + gameID, log);
      } catch (IOException e) {
        String log = "Aborting game! Player " + (myNumber + 1) + " has left the game\n";
        System.out.print(log);
        server.log(log, server.getPort());
        interrupt();
        server.shutdown(nameOfTheGame + " " + myNumber + " " + gameID, log);
      }
    }
  }
Exemplo n.º 3
0
 public ContentContainer() {
   if (Server.TRACE_CREATE_AND_FINALIZE)
     Server.log(
         this,
         "++++++++++++++++++++++++++++++++++++++++CREATE",
         Server.MSG_STATE,
         Server.LVL_VERY_VERBOSE);
 }
Exemplo n.º 4
0
 public void finalize() {
   if (Server.TRACE_CREATE_AND_FINALIZE)
     Server.log(
         this,
         "----------------------------------------FINALIZED",
         Server.MSG_STATE,
         Server.LVL_VERY_VERBOSE);
 }
Exemplo n.º 5
0
 /**
  * trennt die Socketverbindung zum entsprechenden Client
  *
  * @exception IOException
  */
 public void closeConnection() {
   try {
     connection.close();
   } catch (IOException e) {
     String log = "player " + (myNumber + 1) + ": error closing connection\n";
     System.out.print(log);
     server.log(log, server.getPort());
   }
 }
Exemplo n.º 6
0
 public boolean isMobileBrowser(String BrowserAgent) {
   if (BrowserAgent == null) return false;
   StringBuilder c_input = new StringBuilder(Server.srv.MOBILE_BROWSER_REGEX);
   c_input.trimToSize();
   Pattern p = Pattern.compile(c_input.toString().toLowerCase());
   Matcher m = p.matcher(BrowserAgent.toLowerCase());
   if (m.find()) {
     Server.log(
         this,
         "found Mobile Browser [" + m.group() + "] (" + BrowserAgent + ")",
         Server.MSG_TRAFFIC,
         Server.LVL_VERBOSE);
     return true;
   } else return false;
 }
Exemplo n.º 7
0
 public boolean canUseTemplateset(TemplateSet t) {
   if (Server.srv.DEFAULT_TEMPLATESET == null || t == null) return true;
   StringBuffer defaultTs = new StringBuffer(Server.srv.DEFAULT_TEMPLATESET);
   if (defaultTs != null) {
     StringTokenizer st = new StringTokenizer(defaultTs.toString(), ",");
     while (st.hasMoreTokens()) {
       StringBuilder templateName = new StringBuilder(st.nextToken());
       if (templateName.toString().equals(t.getName())) return true;
     }
   }
   if (Server.DEBUG) {
     StringBuffer scn = new StringBuffer();
     scn.append(" can not use Template ");
     scn.append(t.getName());
     Server.log(this, scn.toString(), Server.MSG_TRAFFIC, Server.LVL_MINOR);
   }
   return false;
 }
Exemplo n.º 8
0
 /**
  * append the cookie-header-field to the given StringBuffer
  *
  * @param sb the stringbuffer to append the cookie-header-field
  * @return the stringbuffer with the cookie-header-field appended
  */
 public StringBuffer appendCookie(StringBuffer sb, String CookieDomain) {
   if (cookie == null || CookieDomain == null) return sb;
   sb.append("\r\n");
   sb.append("Set-Cookie: FreeCSSession=");
   sb.append(cookie);
   sb.append("; path=/;");
   if (Server.srv.COOKIE_DOMAIN != null) {
     if (Server.DEBUG)
       Server.log(
           "[ContenCointainer]",
           "append FreecsSession = " + CookieDomain,
           Server.MSG_TRAFFIC,
           Server.LVL_VERY_VERBOSE);
     sb.append(" Domain=");
     sb.append(CookieDomain);
   }
   return sb;
 }
Exemplo n.º 9
0
  public String checkTName(User u, String name) {
    if (Server.srv.getProperty("costum.userAgent") == null) return name;

    String browseragent = name;
    if (u != null && u.getUserAgent() != null) {
      browseragent = u.getUserAgent();
    } else return name;

    boolean defaultFile = true;
    String ta[] = Server.srv.getProperty("costum.userAgent").split(",");
    Vector<String> tempAgent = new Vector<String>();
    for (int i = 0; i < ta.length; i++) {
      tempAgent.add(ta[i].trim().toLowerCase());
    }
    int fn = 0;
    int found = 0;
    for (Enumeration<String> e = tempAgent.elements(); e.hasMoreElements(); ) {
      StringBuilder customAgent = new StringBuilder((String) e.nextElement());
      fn++;
      if (browseragent.toLowerCase().indexOf(customAgent.toString().toLowerCase()) >= 0) {
        defaultFile = false;
        Server.log(
            this,
            "Found Browser '" + customAgent + "'(" + u.getUserAgent() + ")",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        found = fn;
        continue;
      } else {
        if (u != null && u.getUserAgent() != null)
          Server.log(
              this,
              "Browser '" + customAgent + "' not found(" + u.getUserAgent() + ")",
              Server.MSG_STATE,
              Server.LVL_VERBOSE);
      }
      customAgent = null;
    }
    StringBuilder fName = null;
    if (defaultFile) {
      return name;
    } else {
      fName = new StringBuilder(name).append("_custom").append(found);
      if (ts == null || u == null | u.getName() == null) return name;
      tpl = ts.getTemplate(fName.toString());
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        fName = new StringBuilder(name).append("_custom");
        tpl = ts.getTemplate(fName.toString());
      }
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found- loading default input File",
            Server.MSG_ERROR,
            Server.LVL_MAJOR);
        return name;
      }
    }
    return fName.toString();
  }