From f483997d33bc59fccfc2cb967d0bef2e29448a02 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 Feb 2017 20:13:06 -0500 Subject: New chat client-side. --- ShiftOS.WinForms/Applications/Chat.cs | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Chat.cs') diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs index 6f37189..14eb023 100644 --- a/ShiftOS.WinForms/Applications/Chat.cs +++ b/ShiftOS.WinForms/Applications/Chat.cs @@ -36,10 +36,6 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { - [MultiplayerOnly] - [Launcher("MUD Chat", true, "al_mud_chat", "Networking")] - [RequiresUpgrade("mud_fundamentals")] - [WinOpen("chat")] public partial class Chat : UserControl, IShiftOSWindow { public Chat(string chatId) @@ -48,13 +44,16 @@ namespace ShiftOS.WinForms.Applications id = chatId; ServerManager.MessageReceived += (msg) => { - if (msg.Name == "cbroadcast") + if (msg.Name == "chat_msgreceived") { try { this.Invoke(new Action(() => { - rtbchat.Text += msg.Contents + Environment.NewLine; + + var cmsg = JsonConvert.DeserializeObject(msg.Contents); + if(id == cmsg.Channel) + rtbchat.AppendText($"[{cmsg.Username}@{cmsg.SystemName}] {cmsg.Message}{Environment.NewLine}"); })); } catch { } @@ -62,15 +61,16 @@ namespace ShiftOS.WinForms.Applications }; } + public void SendMessage(string msg) + { + ServerManager.SendMessage("chat_send", JsonConvert.SerializeObject(new ShiftOS.Objects.ChatMessage(SaveSystem.CurrentSave.Username, SaveSystem.CurrentSave.SystemName, msg, id))); + } + private string id = ""; public void OnLoad() { - var save = SaveSystem.CurrentSave; - ServerManager.SendMessage("chat_join", $@"{{ - id: ""{id}"", - user: {JsonConvert.SerializeObject(save)} -}}"); + SendMessage("User has joined the chat."); } public void OnSkinLoad() @@ -79,12 +79,8 @@ namespace ShiftOS.WinForms.Applications public bool OnUnload() { - var save = SaveSystem.CurrentSave; - ServerManager.SendMessage("chat_leave", $@"{{ - id: ""{id}"", - user: {JsonConvert.SerializeObject(save)} -}}"); - + SendMessage("User has left the chat."); + id = null; return true; } @@ -105,11 +101,7 @@ namespace ShiftOS.WinForms.Applications var save = SaveSystem.CurrentSave; - ServerManager.SendMessage("chat", $@"{{ - id: ""{id}"", - user: {JsonConvert.SerializeObject(save)}, - msg: ""{txtuserinput.Text}"" -}}"); + SendMessage(txtuserinput.Text); txtuserinput.Text = ""; } } -- cgit v1.2.3