Class ServiceBase

java.lang.Object
br.net.dd.netherwingcore.bnetserver.services.ServiceBase
Direct Known Subclasses:
AuthenticationService, ConnectionService, GameUtilitiesService

public abstract class ServiceBase extends Object
  • Constructor Details

    • ServiceBase

      public ServiceBase()
  • Method Details

    • getServiceHash

      public abstract int getServiceHash()
      Base class for all services. Each service must implement the getServiceHash method to return its unique hash, and the callServerMethod to handle incoming RPC calls.
    • callServerMethod

      public abstract void callServerMethod(Session session, int token, int methodId, MessageBuffer buffer)
      Handles an incoming RPC call for this service. The methodId identifies which method is being called, and the buffer contains the serialized request data.
      Parameters:
      session - the session from which the call originated
      token - the authentication token associated with the call
      methodId - the ID of the method being called
      buffer - the buffer containing the serialized request data
    • parseMessage

      protected <T extends com.google.protobuf.Message> T parseMessage(MessageBuffer buffer, com.google.protobuf.Message.Builder builder, String methodName)
      Utility method to parse a protobuf message from a MessageBuffer. It takes a protobuf Message.Builder and attempts to merge the data from the buffer into it. If successful, it builds and returns the message. If parsing fails, it logs an error and returns null.
      Type Parameters:
      T - the type of protobuf message being parsed
      Parameters:
      buffer - the buffer containing the serialized message data
      builder - the protobuf Message.Builder to use for parsing
      methodName - the name of the method being parsed (for logging purposes)
      Returns:
      the parsed protobuf message, or null if parsing failed
    • sendResponse

      protected void sendResponse(Session session, int token, com.google.protobuf.Message response)
      Utility method to send a protobuf message as a response to the client. It takes the session to send the response to, the authentication token, and the protobuf message to send. It serializes the message and sends it using the session's sendResponse method.
      Parameters:
      session - the session to send the response to
      token - the authentication token associated with the response
      response - the protobuf message to send as a response
    • sendErrorResponse

      protected void sendErrorResponse(Session session, int token, BattlenetRpcErrorCode errorCode)
      Utility method to send an error response to the client. It takes the session to send the response to, the authentication token, and the error code to send. It uses the session's sendResponse method to send the error code.
      Parameters:
      session - the session to send the error response to
      token - the authentication token associated with the error response
      errorCode - the error code to send