private void DispatchCommand(InterChatCommandMsg msg) { switch ((InterChatCommandType) msg.TypeCode) { case InterChatCommandType.InformLoggedUsers: _userMap.Clear(); if (!string.IsNullOrWhiteSpace(msg.Content)) { foreach (var each in msg.Content.Split('|')) { KeyValuePair<string, Color> userInfo; if (ParseUser(each, out userInfo)) _userMap.Add(userInfo.Key, userInfo.Value); } } break; case InterChatCommandType.InformLoggedUser: { KeyValuePair<string, Color> userInfo; if (ParseUser(msg.Content, out userInfo)) _userMap.Add(userInfo.Key, userInfo.Value); } break; case InterChatCommandType.InformLogoutUser: _userMap.Remove(msg.Content); break; case InterChatCommandType.ChangeColor: { KeyValuePair<string, Color> userInfo; if (ParseUser(msg.Content, out userInfo) && _userMap.ContainsKey(userInfo.Key)) _userMap[userInfo.Key] = userInfo.Value; } break; case InterChatCommandType.Speech: { var mp3Bytes = Convert.FromBase64String(msg.Content); var tempFile = Path.GetTempFileName() + ".mp3"; File.WriteAllBytes(tempFile, mp3Bytes); var player = new WMPLib.WindowsMediaPlayer {URL = tempFile}; player.controls.play(); } break; } if (InvokeRequired) Invoke(new MethodInvoker(UpdateUsers)); else UpdateUsers(); }
private void SendCommand(InterChatCommandType type, object value) { var msg = new InterChatCommandMsg {TypeCode = (int) type, Content = Convert.ToString(value)}; _session.Send(msg); }
private void ProcessInterChatCommandMsg(InterChatCommandMsg msg) { switch ((InterChatCommandType)msg.TypeCode) { case InterChatCommandType.CheckUserName: if (msg.Content.As<bool>()) { StartInterChat(); } else { ShowError("Duplicated name: " + textAccountName.Text); UpdateUi(() => { textAccountName.SelectAll(); textAccountName.Focus(); }); } break; } }