public static GameClient ToGameClient(this int sessionId) { var gameClient = WorldMgr.GetClientBySessionId((ushort)sessionId); Condition.Requires(gameClient != null, "gameClient"); return(gameClient); }
private async Task PerformSync() { int changes = 0; using (var call = rpc.ListClients(new ListClientsRequest())) { while (await call.ResponseStream.MoveNext()) { var clt = call.ResponseStream.Current; var gsClient = WorldMgr.GetClientBySessionId((ushort)clt.SessionId); // =============== Below this point we are not sure if the RS client is valid ============= if (clt.IsKnown && (gsClient == null || clt.UniqueId != gsClient.RegionServerUniqueId || gsClient.RegionServer != this)) { // RS should not know about this client as it doesn't exist or is the wrong one await rpc.RemoveClientAsync(new RemoveClientRequest() { SessionId = clt.SessionId }); clt.IsKnown = false; changes++; } // =============== Below this point we assume that there is a valid gs client ============= if (gsClient == null) { continue; // Client wasn't supposed to exist } if (gsClient.RegionServer != this) { continue; // We're not responsible for this client, so don't interferere } if (clt.IsKnown && !string.IsNullOrEmpty(clt.Endpoint) && clt.Endpoint != gsClient.RegionServerUdpEndpoint) { // RS knows, and GS should know about this valid client as well gsClient.RegionServerUdpEndpoint = clt.Endpoint; changes++; } if (!clt.IsKnown) { // RS should know about this client await AddClientToRegion(gsClient); changes++; } bool newUdpState = clt.IsKnown && clt.Endpoint.Length > 0; changes += (newUdpState != gsClient.RegionServerUdpActivated) ? 1 : 0; gsClient.RegionServerUdpActivated = newUdpState; } } if (changes > 0) { Log.InfoFormat("{1} sycned {0} changes", changes, this); } }