Class ServiceBase
java.lang.Object
br.net.dd.netherwingcore.bnetserver.services.ServiceBase
- Direct Known Subclasses:
AuthenticationService, ConnectionService, GameUtilitiesService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcallServerMethod(Session session, int token, int methodId, MessageBuffer buffer) Handles an incoming RPC call for this service.abstract intBase class for all services.protected <T extends com.google.protobuf.Message>
TparseMessage(MessageBuffer buffer, com.google.protobuf.Message.Builder builder, String methodName) Utility method to parse a protobuf message from a MessageBuffer.protected voidsendErrorResponse(Session session, int token, BattlenetRpcErrorCode errorCode) Utility method to send an error response to the client.protected voidsendResponse(Session session, int token, com.google.protobuf.Message response) Utility method to send a protobuf message as a response to the client.
-
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 originatedtoken- the authentication token associated with the callmethodId- the ID of the method being calledbuffer- 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 databuilder- the protobuf Message.Builder to use for parsingmethodName- the name of the method being parsed (for logging purposes)- Returns:
- the parsed protobuf message, or null if parsing failed
-
sendResponse
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 totoken- the authentication token associated with the responseresponse- the protobuf message to send as a response
-
sendErrorResponse
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 totoken- the authentication token associated with the error responseerrorCode- the error code to send
-