public override async Task <Null> Broadacast(BroadacastRequest request, ServerCallContext context) { // 연결된 모든 서버로 메시지를 전송하고 이 서버들에 연결된 모든 유저로 메시지를 전달하는 예시 var client = clients.GetClient <K2B.ServerManager.ServerManagerClient>(remoteConfig.ServerManagerAddress); await client.BroadcastAsync(new K2B.PushRequest { PushMessage = new K2B.PushRequest.Types.PushResponse { Type = K2B.PushRequest.Types.PushResponse.Types.PushType.Message, Message = request.Message } }, header); return(new Null()); }
internal static async Task <bool> IsOnline(string userId, string pushBackendAddress, Metadata backendHeader) { var client = clients.GetClient <SessionHost.SessionHostClient>(pushBackendAddress); // 연결되어있는 서버(Host)에 직접 호출 var response = await client.IsOnlineAsync(new IsOnlineRequest { UserId = userId }, backendHeader); return(response.Result == IsOnlineResponse.Types.ResultType.Online); }
public override async Task <KickUserResponse> KickUser(KickUserRequest request, ServerCallContext context) { string pushBackendAddress; lock (sessions) { if (sessions.TryGetValue(request.UserId, out pushBackendAddress) == false) { return(new KickUserResponse { Result = KickUserResponse.Types.ResultType.NotExist }); } } var client = clients.GetClient <SessionHost.SessionHostClient>(pushBackendAddress); return(await client.KickUserAsync(request, header)); }
private async Task <bool> Register() { var client = clients.GetClient <ServerManager.ServerManagerClient>(localConfig.ServerManagerAddress); var req = new RegisterRequest { Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "", ServerId = localConfig.ServerId, ListeningPort = localConfig.ListeningPort, PublicIp = Util.GetPublicIp(), // backend 전용인 경우 null ServiceScheme = localConfig.ServiceScheme, HasServerManager = localConfig.HasServerManager, // backend unique services HasSessionManager = localConfig.HasSessionManager, // frontend services HasPush = localConfig.HasPushService, HasInit = localConfig.HasInitService, HasPushSample = localConfig.HasPushSampleService, HasSimpleSample = localConfig.HasSimpleSampleService, }; try { var rsp = await client.RegisterAsync(req, header); if (rsp.Result == RegisterResponse.Types.ResultType.Ok) { remoteConfig.ServerManagerAddress = rsp.ServerManagementAddress; remoteConfig.SessionManagerAddress = rsp.UserSessionAddress; remoteConfig.BackendListeningAddress = rsp.BackendListeningAddress; // Register 에 의해 private IP 가 결정되기때문에 이 이후부터 사용 가능. remoteConfig.Registered = true; // remoteConfig 사용 가능 flag return(true); } logger.LogWarning($"Unable to register this server to ServerManager : {rsp.Result}"); } catch (RpcException e) { logger.LogWarning($"ERROR on register to {localConfig.ServerManagerAddress} : {e.Status.Detail}"); } return(false); }
public override Task <Null> UpdateBackend(UpdateBackendRequest request, ServerCallContext context) { logger.LogInformation($"Updating SessionManager {remoteConfig.SessionManagerAddress} to {request.SessionManagerAddress} "); if (remoteConfig.SessionManagerAddress == request.SessionManagerAddress) // ServerManager 가 복구된 경우 ServerManager 가 SessionServer 의 정보를 알수가 없어 UpdateBackend 를 보낼 수 있다. { return(Task.FromResult(new Null())); } remoteConfig.SessionManagerAddress = request.SessionManagerAddress; if (string.IsNullOrEmpty(request.SessionManagerAddress) == false && // SessionManager 복구된 경우 localConfig.HasPushService) // Push service 에서 { // SessionManager 와 user 동기화 var client = clients.GetClient <SessionManager.SessionManagerClient>(request.SessionManagerAddress); Frontend.PushService.Pusher.SyncUsersToSessionManager(client, remoteConfig.BackendListeningAddress, headers, logger); } return(Task.FromResult(new Null())); }