private void CommandRecieved(object sender, CommandEventArgs e) { if (e.Command.CommandType == CommandType.UserDataInform) { client.Wins = int.Parse(e.Command.Data.Split(':')[0]); client.Losses = int.Parse(e.Command.Data.Split(':')[1]); } if (e.Command.CommandType == CommandType.UsernameRequest) { if (e.Command.Data.ToLower() == "false") { client.SignOut(); MessageBox.Show(i18n.GetText("userNameInUse"), i18n.GetText("invalidUsernameTitle"), MessageBoxButtons.OK); client.Disconnect(); } else if (e.Command.Data.ToLower() == "true") { client.CommandRecieved -= CommandRecieved; if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate { chat = new ChatForm(ref client, this); chat.Show(); Hide(); })); } else { chat = new ChatForm(ref client, this); chat.Show(); Hide(); } } } }
private void ChatForm_FormClosing(object sender, FormClosingEventArgs e) { client.SignOut(); Thread.Sleep(1000); //Delay ensures message is completely sent before exiting program client.Disconnect(); }