private void SendMessage() { //we need to send message out string user = ""; if (string.IsNullOrEmpty(MultiPlayerManager.Instance().lastSender)) //server will broadcast the message to everyone { user = MultiPlayerManager.IsServer() ? string.Join("", MultiPlayerManager.OnlineTrains.Players.Keys.Select((string k) => $"{k}\r")) + "0END" : "0Server\r0END"; } string msg = messageText.ToString(); int index = msg.IndexOf(':'); if (index > 0) { msg = messageText.ToString(index + 1, messageText.Length - index - 1); IEnumerable <string> onlinePlayers = messageLabel.Text.Substring(0, index) .Split(',') .Select((string n) => n.Trim()) .Where((string nt) => MultiPlayerManager.OnlineTrains.Players.ContainsKey(nt)) .Select((string nt) => $"{nt}\r"); string newUser = string.Join("", onlinePlayers); if (newUser.Length > 0) { user = newUser; } user += "0END"; } string msgText = new MSGText(MultiPlayerManager.GetUserName(), user, msg).ToString(); try { MultiPlayerManager.Notify(msgText); } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 // Do not catch general exception types { } finally { Visible = false; messageText.Clear(); game.Window.TextInput -= Window_TextInput; keyboardInput.ResumeFromOverlayInput(); } }
/// <summary> /// Retrieve a formatted list <see cref="ListLabel"/>s to be displayed as an in-browser Track Monitor. /// </summary> /// <param name="viewer">The Viewer to read train data from.</param> /// <returns>A list of <see cref="ListLabel"/>s, one per row of the popup.</returns> public IEnumerable <ListLabel> MultiPlayerWindowList(Viewer viewer) { //Update data keyPressed = ""; labels = new List <ListLabel>(); void AddLabel(ListLabel label) { CheckLabel(ref label); } void AddSeparator() => AddLabel(new ListLabel { FirstCol = "Sprtr", }); labels.Clear(); UpdateDataEnded = false; // First Block // Client and server may have a time difference. var time = FormatStrings.FormatTime(viewer.Simulator.ClockTime + (MultiPlayerManager.IsClient() ? MultiPlayerManager.Instance().serverTimeDifference : 0)); AddLabel(new ListLabel { FirstCol = $"{CatalogManager.Catalog.GetString("Time")}: {time}", LastCol = "" }); // Separator AddSeparator(); // MultiPlayer if (MultiPlayerManager.IsMultiPlayer()) { string text = MultiPlayerManager.Instance().GetOnlineUsersInfo(); string multiPlayerStatus = MultiPlayerManager.IsServer() ? $"{CatalogManager.Catalog.GetString("Dispatcher")} ({MultiPlayerManager.Client.UserName})" : MultiPlayerManager.Instance().AmAider ? CatalogManager.Catalog.GetString("Helper") : MultiPlayerManager.IsClient() ? $"{CatalogManager.Catalog.GetString("Client")} ({MultiPlayerManager.Client.UserName})" : ""; var status = $"{CatalogManager.Catalog.GetString("Status")}: {multiPlayerStatus}"; AddLabel(new ListLabel { FirstCol = status, LastCol = "" }); AddLabel(new ListLabel()); // Number of player and trains foreach (var t in text.Split('\t')) { AddLabel(new ListLabel { FirstCol = $"{t}", LastCol = "" }); } AddLabel(new ListLabel()); } else if (Simulator.Instance.Confirmer != null) { var status = $"{CatalogManager.Catalog.GetString("Status")}: {CatalogManager.Catalog.GetString("Connection to the server is lost, will play as single mode")}"; AddLabel(new ListLabel { FirstCol = status, LastCol = "" }); AddLabel(new ListLabel()); } AddLabel(new ListLabel()); UpdateDataEnded = true; return(labels); }
/// <summary> /// SkyDrawer constructor /// </summary> public MSTSSkyDrawer(Viewer viewer) { MSTSSkyViewer = viewer; MSTSSkyMaterial = viewer.MaterialManager.Load("MSTSSky"); // Instantiate classes MSTSSkyMesh = new MSTSSkyMesh(MSTSSkyViewer.RenderProcess); MSTSSkyVectors = new SunMoonPos(); //viewer.World.MSTSSky.MSTSSkyMaterial.Viewer.MaterialManager.sunDirection.Y < 0 // Set default values mstsskyseasonType = (int)MSTSSkyViewer.Simulator.Season; date.ordinalDate = 82 + mstsskyseasonType * 91; // TODO: Set the following three externally from ORTS route files (future) date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2010; // Default wind speed and direction mstsskywindSpeed = 5.0f; // m/s (approx 11 mph) mstsskywindDirection = 4.7f; // radians (approx 270 deg, i.e. westerly) // The following keyboard commands are used for viewing sky and weather effects in "demo" mode. // Control- and Control+ for overcast, Shift- and Shift+ for fog and - and + for time. // Don't let multiplayer clients adjust the weather. if (!MultiPlayerManager.IsClient()) { // Overcast ranges from 0 (completely clear) to 1 (completely overcast). viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastIncrease, KeyEventType.KeyDown, (GameTime gameTIme) => { mstsskyovercastFactor = (float)MathHelperD.Clamp(mstsskyovercastFactor + gameTIme.ElapsedGameTime.TotalSeconds / 10, 0, 1); }); viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastDecrease, KeyEventType.KeyDown, (GameTime gameTIme) => { mstsskyovercastFactor = (float)MathHelperD.Clamp(mstsskyovercastFactor - gameTIme.ElapsedGameTime.TotalSeconds / 10, 0, 1); }); // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions). viewer.UserCommandController.AddEvent(UserCommand.DebugFogIncrease, KeyEventType.KeyDown, (GameTime gameTIme) => { mstsskyfogDistance = (float)MathHelperD.Clamp(mstsskyfogDistance - gameTIme.ElapsedGameTime.TotalSeconds * mstsskyfogDistance, 10, 100000); }); viewer.UserCommandController.AddEvent(UserCommand.DebugFogDecrease, KeyEventType.KeyDown, (GameTime gameTIme) => { mstsskyfogDistance = (float)MathHelperD.Clamp(mstsskyfogDistance + gameTIme.ElapsedGameTime.TotalSeconds * mstsskyfogDistance, 10, 100000); }); } // Don't let clock shift if multiplayer. if (!MultiPlayerManager.IsMultiPlayer()) { // Shift the clock forwards or backwards at 1h-per-second. viewer.UserCommandController.AddEvent(UserCommand.DebugClockForwards, KeyEventType.KeyDown, (GameTime gameTIme) => { MSTSSkyViewer.Simulator.ClockTime += gameTIme.ElapsedGameTime.TotalSeconds * 3600; }); viewer.UserCommandController.AddEvent(UserCommand.DebugClockBackwards, KeyEventType.KeyDown, (GameTime gameTIme) => { MSTSSkyViewer.Simulator.ClockTime -= gameTIme.ElapsedGameTime.TotalSeconds * 3600; }); } // Server needs to notify clients of weather changes. if (MultiPlayerManager.IsServer()) { viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastIncrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification); viewer.UserCommandController.AddEvent(UserCommand.DebugOvercastDecrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification); viewer.UserCommandController.AddEvent(UserCommand.DebugFogIncrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification); viewer.UserCommandController.AddEvent(UserCommand.DebugFogDecrease, KeyEventType.KeyReleased, SendMultiPlayerSkyChangeNotification); } }