Esempio n. 1
0
 /**
  * Sends a response packet from the server to the client.
  *
  * <p>Synchronized so that only one thread can send a client a message at a time.
  *
  * @param packet the response packet
  */
 public synchronized void sendResponse(Packet packet) {
   try {
     session.getRemote().sendString(packet.getJson().toString());
   } catch (IOException ioe) {
     System.out.println(
         "Sending response failed, session id = " + session.getRemoteAddress().toString());
   }
 }
Esempio n. 2
0
 /**
  * Delivers a packet that was received from the client.
  *
  * @param packet the wrapper around the JSON object containing the message
  */
 public void recvRequest(Packet packet) {
   int suppliedId = packet.getPlayerId();
   if (player == null && suppliedId != Packet.PLAYER_ID_NOT_LOGGED_IN) {
     // impersonation attempt
     throw new ClientModifiedException(
         "hacking attempt detected: not logged in, but supplied id = " + packet.getPlayerId());
   } else if (player != null && packet.getPlayerId() != player.getId()) {
     // impersonation attempt
     throw new ClientModifiedException(
         "hacking attempt detected: wrong player id, is "
             + player.getId()
             + " but supplied "
             + packet.getPlayerId());
   }
   // passed the hacking checks, find the handler
   String action = packet.getAction();
   PacketHandler handler =
       (player == null) ? packetHandlersNoAuth.get(action) : packetHandlers.get(action);
   if (handler == null) {
     throw new ClientModifiedException("hacking attempt detected: action = " + action);
   }
   // finally, handle the packet
   handler.handlePacket(this, packet);
 }