diff options
| author | Michael <[email protected]> | 2017-02-12 20:13:06 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-12 20:13:06 -0500 |
| commit | f483997d33bc59fccfc2cb967d0bef2e29448a02 (patch) | |
| tree | dfa536d0957f282da9f833aedd0c3fb41c014ff7 /ShiftOS.WinForms/Applications/Chat.cs | |
| parent | f5f4dcbdb58829707ecbc7ecc20ffdae8c656457 (diff) | |
| download | shiftos_thereturn-f483997d33bc59fccfc2cb967d0bef2e29448a02.tar.gz shiftos_thereturn-f483997d33bc59fccfc2cb967d0bef2e29448a02.tar.bz2 shiftos_thereturn-f483997d33bc59fccfc2cb967d0bef2e29448a02.zip | |
New chat client-side.
Diffstat (limited to 'ShiftOS.WinForms/Applications/Chat.cs')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Chat.cs | 36 |
1 files changed, 14 insertions, 22 deletions
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<ShiftOS.Objects.ChatMessage>(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 = ""; } } |
