コード例 #1
0
ファイル: Program.cs プロジェクト: ktj007/mmo
        internal void DispatchCommand(MessageSession session, InterChatCommandMsg msg)
        {
            var user = FindUserFromSessionWithLock(session);
            if (user == null)
                return;

            switch ((InterChatCommandType)msg.TypeCode)
            {
                case InterChatCommandType.CheckUserName:
                    // 중복된 유저 이름이 있는지 검사해서 알려준다.
                    session.Send(new InterChatCommandMsg
                        {
                            TypeCode = (int)InterChatCommandType.CheckUserName,
                            Content = user.ToString()
                        });
                    break;

                case InterChatCommandType.ChangeColor:
                    // 자신의 텍스트 색상을 변경한다.
                    user.TextColor = Color.FromArgb(int.Parse(msg.Content));
                    BroadcastCommandMsgWithLock(InterChatCommandType.ChangeColor, user.ToString());
                    break;

                case InterChatCommandType.Speech:
                    // Speech를 수행한다.
                    Task.Factory.StartNew(() => DoSpeech(user.Name, msg.Content));
                    break;
            }
        }
コード例 #2
0
        private void SendCommand(InterChatCommandType type, object value)
        {
            var msg = new InterChatCommandMsg {
                TypeCode = (int)type, Content = Convert.ToString(value)
            };

            _session.Send(msg);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ktj007/mmo
        internal void BroadcastCommandMsgWithNoLock(InterChatCommandType commandType, string content)
        {
            var msg = new InterChatCommandMsg
            {
                TypeCode = (int)commandType,
                Content = content
            };

            foreach (var eachSession in _interChatUserMap.Keys)
                eachSession.Send(msg);
        }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
        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();
            }
        }