@xmobitea/gn-server
Version:
GearN Server by XmobiTea (Pro)
429 lines (428 loc) • 17.3 kB
TypeScript
import { RequestController } from "./GN-app-api/handler/controller/RequestController";
import { OperationEvent } from "./GN-common/entity/operationEvent/OperationEvent";
import { xDatabase } from "./GN-library/xdatabase/lib/xDatabase";
import { SocketApp } from "./GN-startup/SocketApp";
import { HttpApp } from "./GN-startup/HttpApp";
import { IRequestHandler } from "./GN-app-api/handler/controller/handler/base/IRequestHandler";
import { IFacebookService } from "./GN-app-api/service/IFacebookService";
import { IAppleService } from "./GN-app-api/service/IAppleService";
import { ICloudScriptService } from "./GN-app-api/service/ICloudScriptService";
import { ITimerService } from "./GN-app-api/service/ITimerService";
import { OnRunSuccess } from "./GN-library/xbuilder/lib/OnRunSuccess";
import { ApiMiddleware } from "./GN-startup/middleware/ApiMiddleware";
import { IRequestConverterService } from "./GN-app-api/service/IRequestConverterService";
import { IGoogleService } from "./GN-app-api/service/IGoogleService";
import { IAnalyticsService } from "./GN-app-api/service/IAnalyticsService";
import { IPushNotificationService } from "./GN-app-api/service/IPushNotificationService";
import { IEmailService } from "./GN-app-api/service/IEmailService";
import { ICacheService } from "./GN-app-api/service/ICacheService";
import { IConfigService } from "./GN-app-api/service/IConfigService";
import { xGNSettings } from "./GN-library/xsettings/lib/xGNSettings";
import { IPostEventCallbackService, IPreEventCallbackService } from "./GN-app-api/service/IEventCallbackService";
import { IEventCallbackCloudScriptService } from "./GN-app-api/service/EventCallbackService";
import { ICloudScriptEventService } from "./GN-app-api/service/CloudScriptEventService";
import { IGameCenterService } from "./GN-app-api/service/IGameCenterService";
import { IGooglePlayGameService } from "./GN-app-api/service/IGooglePlayGameService";
import { ICountryIPDetailService } from "./GN-app-api/service/ICountryIPDetailService";
import { ServerDetail } from "./GN-library/xdatabase/lib/entity/pro/ServerDetail";
interface CreateIndexesOptions {
unique?: boolean;
sparse?: boolean;
expireAfterSeconds?: number;
}
/**
* Runtime coordinator that connects transports, request dispatch, cross-cutting services, and scheduled jobs.
*/
export declare class GNServer {
/**
* Returns the server version.
* @returns Returns the server version.
*/
static getServerVersion(): string;
private socketApp;
private httpApp;
private apiMiddleware;
private requestController;
private idTypeCase;
private initRootUsername;
private restoreRootPassword;
private xGNSettings;
private xDatabase;
private facebookService;
private appleService;
private googleService;
private googlePlayGameService;
private gameCenterService;
private timerService;
private requestConverterService;
private analyticsService;
private postEventCallbackService;
private preEventCallbackService;
private cloudScriptServiceDic;
private eventCallbackCloudScriptService;
private cloudScriptEventService;
private countryIPDetailService;
private pushNotificationService;
private emailService;
private cacheServiceDic;
private configServiceDic;
private gameIds;
private matchmakingService;
private waitingServerDetailDict;
private postEventCallbackCollection;
/**
* Initializes a new GearN server instance.
*/
constructor();
/**
* Registers the built-in handler graph into the request controller.
*/
init(): void;
/**
* Binds HTTP/socket callbacks, analytics, and cluster event forwarding after transports are injected.
* @param onRunSuccess Provides the callback executed after a successful startup.
*/
run(onRunSuccess?: OnRunSuccess): void;
/**
* Sets the socket app.
* @param socketApp Provides the socket app value used by this operation.
*/
setSocketApp(socketApp: SocketApp): void;
/**
* Sets the HTTP app.
* @param httpApp Provides the HTTP app value used by this operation.
*/
setHttpApp(httpApp: HttpApp): void;
/**
* Sets the API middleware.
* @param apiMiddleware Provides the API middleware value used by this operation.
*/
setApiMiddleware(apiMiddleware: ApiMiddleware): void;
/**
* Returns the API middleware.
* @returns Returns the API middleware.
*/
getApiMiddleware(): ApiMiddleware;
/**
* Returns the socket app.
* @returns Returns the socket app.
*/
getSocketApp(): SocketApp;
/**
* Returns the HTTP app.
* @returns Returns the HTTP app.
*/
getHttpApp(): HttpApp;
/**
* Returns the request controller.
* @returns Returns the request controller.
*/
getRequestController(): RequestController;
/**
* Adds the custom handler.
* @param requestHandler Provides the request handler used by this operation.
* @param onlyAuthenticated Indicates whether only authenticated access is allowed.
*/
addCustomHandler(requestHandler: IRequestHandler, onlyAuthenticated?: boolean): void;
/**
* Returns the custom handler.
* @param operationCode Provides the operation code value used by this operation.
* @returns Returns the custom handler.
*/
getCustomHandler(operationCode: string): IRequestHandler;
/**
* Removes the custom handler.
* @param operationCode Provides the operation code value used by this operation.
*/
removeCustomHandler(operationCode: string): void;
/**
* Creates the index.
* @param collectionName Provides the collection name value used by this operation.
* @param index Provides the index value used by this operation.
* @param options Provides the options value used by this operation.
*/
createIndex(collectionName: string, index: {
[k: string]: any;
}, options?: CreateIndexesOptions): void;
/**
* Executes the log create index workflow.
* @param collectionName Provides the collection name value used by this operation.
* @param index Provides the index value used by this operation.
* @param options Provides the options value used by this operation.
*/
logCreateIndex(collectionName: string, index: {
[k: string]: any;
}, options?: CreateIndexesOptions): void;
/**
* Returns the configuration service.
* @param gameId Provides the game ID value used by this operation.
* @returns Returns the configuration service.
*/
getConfigService(gameId: string): IConfigService;
/**
* Sets the configuration game.
* @param gameId Provides the game ID value used by this operation.
* @param configService Provides the configuration service used by this operation.
*/
setConfigGame(gameId: string, configService: IConfigService): void;
/**
* Sets the ID type case.
* @param idTypeCase Provides the ID type case value used by this operation.
*/
setIdTypeCase(idTypeCase: number): void;
/**
* Returns the ID type case.
*/
getIdTypeCase(): number;
/**
* Sets the restore root password.
* @param restoreRootPassword Provides the restore root password value used by this operation.
*/
setRestoreRootPassword(restoreRootPassword: string): void;
/**
* Returns the restore root password.
*/
getRestoreRootPassword(): string;
/**
* Sets the root username.
* @param initRootUsername Provides the root username value used by this operation.
*/
setInitRootUsername(initRootUsername: string): void;
/**
* Returns the root username.
*/
getInitRootUsername(): string;
/**
* Returns the GearN settings.
* @returns Returns the GearN settings.
*/
getGNSettings(): xGNSettings;
/**
* Returns the database.
* @returns Returns the database.
*/
getDatabase(): xDatabase;
/**
* Returns the cache service.
* @param gameId Provides the game ID value used by this operation.
* @returns Returns the cache service.
*/
getCacheService(gameId: string): ICacheService;
/**
* Sets the cache service.
* @param gameId Provides the game ID value used by this operation.
* @param cacheService Provides the cache service used by this operation.
*/
setCacheService(gameId: string, cacheService: ICacheService): void;
/**
* Returns the facebook service.
* @returns Returns the facebook service.
*/
getFacebookService(): IFacebookService;
/**
* Returns the post event callback service.
* @returns Returns the post event callback service.
*/
getPostEventCallbackService(): IPostEventCallbackService;
/**
* Returns the pre event callback service.
* @returns Returns the pre event callback service.
*/
getPreEventCallbackService(): IPreEventCallbackService;
/**
* Returns the event callback cloud script service.
* @returns Returns the event callback cloud script service.
*/
getEventCallbackCloudScriptService(): IEventCallbackCloudScriptService;
/**
* Returns the cloud script event service.
* @returns Returns the cloud script event service.
*/
getCloudScriptEventService(): ICloudScriptEventService;
/**
* Returns the country IP detail service.
* @returns Returns the country IP detail service.
*/
getCountryIPDetailService(): ICountryIPDetailService;
/**
* Returns the apple service.
* @returns Returns the apple service.
*/
getAppleService(): IAppleService;
/**
* Returns the google service.
* @returns Returns the google service.
*/
getGoogleService(): IGoogleService;
/**
* Returns the google play game service.
* @returns Returns the google play game service.
*/
getGooglePlayGameService(): IGooglePlayGameService;
/**
* Returns the game center service.
* @returns Returns the game center service.
*/
getGameCenterService(): IGameCenterService;
/**
* Returns the timer service.
* @returns Returns the timer service.
*/
getTimerService(): ITimerService;
/**
* Returns the analytics service.
* @returns Returns the analytics service.
*/
getAnalyticsService(): IAnalyticsService;
/**
* Returns the request converter service.
* @returns Returns the request converter service.
*/
getRequestConverterService(): IRequestConverterService;
/**
* Returns the email service.
* @returns Returns the email service.
*/
getEmailService(): IEmailService;
/**
* Returns the push notification service.
* @returns Returns the push notification service.
*/
getPushNotificationService(): IPushNotificationService;
/**
* Returns the cloud script service.
* @param gameId Provides the game ID value used by this operation.
* @returns Returns the cloud script service.
*/
getCloudScriptService(gameId: string): ICloudScriptService;
/**
* Sets the cloud script service.
* @param gameId Provides the game ID value used by this operation.
* @param cloudScriptService Provides the cloud script service used by this operation.
*/
setCloudScriptService(gameId: string, cloudScriptService: ICloudScriptService): Map<string, ICloudScriptService>;
/**
* Broadcasts an event to one user, logs the callback payload, then fans it out through the cluster handler.
* @param userId Indicates whether r ID should be used.
* @param operationEvent Provides the operation event value used by this operation.
*/
sendEventTo(userId: string, operationEvent: OperationEvent): Promise<void>;
/**
* Replays a cluster message locally on the socket layer.
* @param data Provides the data value used by this operation.
*/
private executeSendEventTo;
/**
* Broadcasts an event to one room, logs the callback payload, then fans it out through the cluster handler.
* @param roomId Provides the room ID value used by this operation.
* @param operationEvent Provides the operation event value used by this operation.
*/
sendEventToRoom(roomId: string, operationEvent: OperationEvent): Promise<void>;
/**
* Replays a room broadcast received from the cluster bus on the local node.
* @param data Provides the data value used by this operation.
*/
private executeSendEventToRoom;
/**
* Broadcasts an event to multiple users, logs the callback payload, then fans it out through the cluster handler.
* @param userIds Indicates whether r IDs should be used.
* @param operationEvent Provides the operation event value used by this operation.
*/
sendEventToMoreUser(userIds: string[], operationEvent: OperationEvent): Promise<void>;
/**
* Replays a multi-user broadcast received from the cluster bus on the local node.
* @param data Provides the data value used by this operation.
*/
private executeSendEventToMoreUser;
/**
* Broadcasts an event to every connected player, logs the callback payload, then fans it out through the cluster handler.
* @param operationEvent Provides the operation event value used by this operation.
*/
sendEventToAllPlayer(operationEvent: OperationEvent): Promise<void>;
/**
* Replays a global broadcast received from the cluster bus on the local node.
* @param data Provides the data value used by this operation.
*/
private executeSendEventToAllPlayer;
private executeRevokeAdminAuthToken;
/**
* Proxies room membership changes to the socket transport.
*/
joinRoom(userId: string, roomId: string): void;
/**
* Removes a user from a socket room on the local node.
* @param userId Indicates whether r ID should be used.
* @param roomId Provides the room ID value used by this operation.
*/
leaveRoom(userId: string, roomId: string): void;
/**
* Returns the socket rooms the given user currently belongs to on this node.
* @param userId Indicates whether r ID should be used.
* @returns Returns the rooms.
*/
getRooms(userId: string): Promise<string[]>;
/**
* Clears runtime socket auth state and emits disconnect callbacks for authenticated sockets.
* @param socket Provides the socket value used by this operation.
* @param data Provides the data value used by this operation.
*/
private handleSocketDisconnect;
/**
* Emits the post-auth socket callback once middleware marks the connection as authenticated.
* @param socket Provides the socket value used by this operation.
* @param authInfo Provides the auth info value used by this operation.
*/
private handleSocketAuthenticate;
/**
* Single dispatch point shared by both HTTP and socket transports.
* @param request Provides the request value used by this operation.
* @returns Resolves with the operation result.
*/
private handleOnRequest;
/**
* Polls matchmaking queues for every loaded game.
*/
private handleMatchmaking;
/**
* Periodically evicts expired cache entries for every loaded game.
*/
private handleRemoveCacheInvalidData;
/**
* Handles the matchmaking for game.
* @param gameId Provides the game ID value used by this operation.
*/
private handleMatchmakingForGame;
/**
* Requests the match server detail.
* @param gameId Provides the game ID value used by this operation.
* @param matchmakingTicketCanMatch Provides the matchmaking ticket can match value used by this operation.
*/
private requestMatchServerDetail;
/**
* Stores the allocated runtime server detail and marks every related ticket as matched.
* @param gameId Provides the game ID value used by this operation.
* @param matchId Provides the match ID value used by this operation.
* @param serverDetail Provides the server detail value used by this operation.
* @param ticketIds Provides the ticket IDs value used by this operation.
*/
setMatchServerDetail(gameId: string, matchId: string, serverDetail: ServerDetail, ticketIds: string[]): void;
/**
* Cancels waiting tickets when runtime server allocation fails or times out.
* @param gameId Provides the game ID value used by this operation.
* @param matchId Provides the match ID value used by this operation.
* @param ticketIds Provides the ticket IDs value used by this operation.
* @param reason Provides the reason value used by this operation.
*/
setMatchServerDetailFailed(gameId: string, matchId: string, ticketIds: string[], reason: string): void;
/**
* Returns the game IDs.
* @returns Returns the game IDs.
*/
getGameIds(): string[];
/**
* Returns whether the current runtime is the primary cluster node.
* @returns Returns the operation result.
*/
isPrimary(): boolean;
}
export {};