Package net.tacospice.stevenet.NetworkMessages

Examples of net.tacospice.stevenet.NetworkMessages.Disconnect


          // Already registered?
          if (connection.name != null)
          {
            logMessage("Discarded login from " + c.getID() + " (already logged in as " + connection.name + ")");

            Disconnect dc = new Disconnect();
            dc.reason = Reason.AlreadyLoggedIn;
            sendToTCP(connection.getID(), dc);

            connection.close();

            return;
          }

          // Invalid name?
          String name = ((Login) object).name;

          if (name == null)
          {
            logMessage("Discarded login from " + c.getRemoteAddressTCP() + " (name missing)");

            Disconnect dc = new Disconnect();
            dc.reason = Reason.NoName;
            sendToTCP(connection.getID(), dc);

            connection.close();

            return;
          }

          name = name.trim();
          if (name.length() == 0)
          {
            logMessage("Discarded login from " + c.getRemoteAddressTCP() + " (name has zero length)");

            Disconnect dc = new Disconnect();
            dc.reason = Reason.ZeroNameLength;
            sendToTCP(connection.getID(), dc);

            connection.close();

            return;
          }

          // Store the name on the connection
          connection.name = name;

          // TODO: verify connection with ServerEventHandler
          clientConnected(connection);

          // Replicate existing nodes
          replicateAllNodes(connection.getID());

          // Notify users
          UserConnect uc = new UserConnect();
          uc.name = connection.name;
          sendToAllTCP(uc);

          logMessage("Accepted login from " + c.getRemoteAddressTCP() + ": " + name);

          return;
        }

        // Ignore any other messages by unregistered users
        if (connection.name == null)
        {
          // TODO: disconnect user?
          logMessage("Disconnected " + c.getRemoteAddressTCP() + " (not registered)");

          Disconnect dc = new Disconnect();
          dc.reason = Reason.DidNotRegister;
          sendToTCP(connection.getID(), dc);

          connection.close();
          return;
View Full Code Here

TOP

Related Classes of net.tacospice.stevenet.NetworkMessages.Disconnect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.