aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications/Chat.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-01-08 09:57:10 -0500
committerMichael <[email protected]>2017-01-08 09:57:10 -0500
commitf30dcf5ef41d54c588d7b42c48be8d941abba72e (patch)
tree7705f99b965673b1c034ac2b1c56e65072c827df /ShiftOS.WinForms/Applications/Chat.cs
parent69dfad54724d4176dfce238a8d7e73970e6eef24 (diff)
downloadshiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.gz
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.bz2
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.zip
Initial upload
Diffstat (limited to 'ShiftOS.WinForms/Applications/Chat.cs')
-rw-r--r--ShiftOS.WinForms/Applications/Chat.cs93
1 files changed, 93 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs
new file mode 100644
index 0000000..3fb68e3
--- /dev/null
+++ b/ShiftOS.WinForms/Applications/Chat.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Newtonsoft.Json;
+using ShiftOS.Engine;
+
+namespace ShiftOS.WinForms.Applications
+{
+ [MultiplayerOnly]
+ [Launcher("MUD Chat", true, "al_mud_chat")]
+ [RequiresUpgrade("mud_fundamentals")]
+ [WinOpen("chat")]
+ public partial class Chat : UserControl, IShiftOSWindow
+ {
+ public Chat(string chatId)
+ {
+ InitializeComponent();
+ id = chatId;
+ ServerManager.MessageReceived += (msg) =>
+ {
+ if (msg.Name == "cbroadcast")
+ {
+ try
+ {
+ this.Invoke(new Action(() =>
+ {
+ rtbchat.Text += msg.Contents + Environment.NewLine;
+ }));
+ }
+ catch { }
+ }
+ };
+ }
+
+ private string id = "";
+
+ public void OnLoad()
+ {
+ var save = SaveSystem.CurrentSave;
+ ServerManager.SendMessage("chat_join", $@"{{
+ id: ""{id}"",
+ user: {JsonConvert.SerializeObject(save)}
+}}");
+ }
+
+ public void OnSkinLoad()
+ {
+ }
+
+ public bool OnUnload()
+ {
+ var save = SaveSystem.CurrentSave;
+ ServerManager.SendMessage("chat_leave", $@"{{
+ id: ""{id}"",
+ user: {JsonConvert.SerializeObject(save)}
+}}");
+
+ return true;
+ }
+
+ public void OnUpgrade()
+ {
+ }
+
+ private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
+ {
+ e.SuppressKeyPress = true;
+ }
+
+ private void txtuserinput_KeyDown(object sender, KeyEventArgs e)
+ {
+ if(e.KeyCode == Keys.Enter)
+ {
+ e.SuppressKeyPress = true;
+
+ var save = SaveSystem.CurrentSave;
+
+ ServerManager.SendMessage("chat", $@"{{
+ id: ""{id}"",
+ user: {JsonConvert.SerializeObject(save)},
+ msg: ""{txtuserinput.Text}""
+}}");
+ txtuserinput.Text = "";
+ }
+ }
+ }
+}