public void HandleChangeSubspace(ClientStructure client, WarpChangeSubspaceMsgData message) { if (message.PlayerName != client.PlayerName) { return; } var oldSubspace = client.Subspace; var newSubspace = message.Subspace; if (oldSubspace != newSubspace) { var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <WarpChangeSubspaceMsgData>(); msgData.PlayerName = client.PlayerName; msgData.Subspace = message.Subspace; MessageQueuer.RelayMessage <WarpSrvMsg>(client, msgData); if (newSubspace != -1) { client.Subspace = newSubspace; //If client stopped warping and there's nobody in that subspace, remove it if (!ServerContext.Clients.Any(c => c.Value.Subspace == oldSubspace)) { WarpSystem.RemoveSubspace(oldSubspace); VesselRelaySystem.RemoveSubspace(oldSubspace); } } } }
public static void DisconnectClient(ClientStructure client, string reason = "") { if (!string.IsNullOrEmpty(reason)) { LunaLog.Debug($"{client.PlayerName} sent Connection end message, reason: {reason}"); } VesselUpdateRelaySystem.RemovePlayer(client); //Remove Clients from list if (ServerContext.Clients.ContainsKey(client.Endpoint)) { ServerContext.Clients.TryRemove(client.Endpoint, out client); LunaLog.Debug($"Online Players: {ServerContext.PlayerCount}, connected: {ServerContext.Clients.Count}"); } if (client.ConnectionStatus != ConnectionStatus.Disconnected) { client.ConnectionStatus = ConnectionStatus.Disconnected; LmpPluginHandler.FireOnClientDisconnect(client); if (client.Authenticated) { ChatSystem.RemovePlayer(client.PlayerName); var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <PlayerConnectionLeaveMsgData>(); msgData.PlayerName = client.PlayerName; MessageQueuer.RelayMessage <PlayerConnectionSrvMsg>(client, msgData); LockSystem.ReleasePlayerLocks(client); if (!ServerContext.Clients.Any(c => c.Value.Subspace == client.Subspace)) { WarpSystem.RemoveSubspace(client.Subspace); VesselRelaySystem.RemoveSubspace(client.Subspace); } } try { client.Connection?.Disconnect(reason); } catch (Exception e) { LunaLog.Debug($"Error closing client Connection: {e.Message}"); } ServerContext.LastPlayerActivity = ServerContext.ServerClock.ElapsedMilliseconds; } }