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(); } }
public static void RegisterInputEvents(Viewer viewer) { if (null == viewer) { throw new ArgumentNullException(nameof(viewer)); } //In Multiplayer, I maybe the helper, but I can request to be the controller // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs viewer.UserCommandController.AddEvent(UserCommand.GameRequestControl, KeyEventType.KeyPressed, MultiPlayerManager.RequestControl); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph1, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "PANTO1", (++panto1) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph2, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "PANTO2", (++panto2) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph3, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "PANTO3", (++panto3) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph4, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "PANTO4", (++panto4) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlWiper, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "WIPER", (++wiper) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlDoorLeft, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "DOORL", (++doorLeft) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlDoorRight, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "DOORR", (++doorRight) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlMirror, KeyEventType.KeyPressed, () => MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "MIRRORS", (++mirrors) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightIncrease, KeyEventType.KeyPressed, () => { headlight++; if (headlight >= 3) { headlight = 2; } MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "HEADLIGHT", headlight).ToString()); }); viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightDecrease, KeyEventType.KeyPressed, () => { headlight--; if (headlight < 0) { headlight = 0; } MultiPlayerManager.Notify(new MSGEvent(MultiPlayerManager.GetUserName(), "HEADLIGHT", headlight).ToString()); }); }