Guest User

Untitled

a guest
Jun 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public void handle(HttpExchange exchange) throws IOException{
  2.        
  3.         //If it's not a post
  4.         if(!(exchange.getRequestMethod().equals("POST"))) {
  5.            
  6.                 logError(exchange, "Bad Method: "+exchange.getRequestMethod());
  7.                 exchange.sendResponseHeaders(HttpURLConnection.HTTP_BAD_METHOD, 0);
  8.                 exchange.close();
  9.                 return;
  10.            
  11.         }
  12.        
  13.         //If it's not casio
  14.         //if(exchange.getRemoteAddress().getAddress().getAddress()!= CASIO){
  15.            
  16.         //  logError(exchange, "Forbidden");
  17.         //  exchange.sendResponseHeaders(HttpURLConnection.HTTP_FORBIDDEN, 0);
  18.         //  exchange.close();
  19.         //  return;
  20.            
  21.         //}
  22.        
  23.         BufferedReader body = new BufferedReader(new InputStreamReader(exchange.getRequestBody()));
  24.         //Iterate through the attached lines
  25.         for (String line = body.readLine(); line != null; line = body.readLine()) {
  26.            
  27.             String[] values= line.split(Character.toString('\u001b'));
  28.             String user=values[1];
  29.             String message= values[2];
  30.             int type= Integer.decode(values[3]);
  31.            
  32.             switch(type){
  33.                 case 0: bot.error(user, message); break;
  34.                 case 1: bot.say(user, message); break;
  35.                 case 2: bot.channel(user, message); break;
  36.                 case 3: bot.action(user, message); break;
  37.             }
  38.            
  39.         }
  40.         exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
  41.         exchange.close();
  42.        
  43.     }
Add Comment
Please, Sign In to add comment