예제 #1
0
        public void Parse(string command)
        {
            var commands = command.Split(' ');

            switch (commands[0].ToLower())
            {
            case "attack":
            case "a":
                var target = commands.Length > 1 ? commands[1] : string.Empty;
                Attack?.Invoke(target);
                break;

            case "east":
            case "e":
                East?.Invoke();
                break;

            case "help":
                Help?.Invoke();
                break;

            case "north":
            case "n":
                North?.Invoke();
                break;

            case "run":
                Run?.Invoke();
                break;

            case "south":
            case "s":
                South?.Invoke();
                break;

            case "west":
            case "w":
                West?.Invoke();
                break;

            default:
                Unknown?.Invoke();
                break;
            }
        }
예제 #2
0
        private void SocketOnMessageReceived(object sender, MessageReceivedEventArgs messageReceivedEventArgs)
        {
            PubSubMessageEventArgs msg;
            var type = parser.Parse(messageReceivedEventArgs.Message, out msg);

            // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags (enum is not really using flags)
            if ((type & PubSubMessageType.Unknown) > 0)
            {
                Unknown?.Invoke(this, (UnknownMessageEventArgs)msg);
                return;
            }

            // ReSharper disable once SwitchStatementMissingSomeCases (handled by the if above)
            switch (type)
            {
            case PubSubMessageType.Response:
                Response?.Invoke(this, (ResponseMessageEventArgs)msg);
                break;

            case PubSubMessageType.Pong:
                pongTimeoutTimer.Stop();
                Pong?.Invoke(this, System.EventArgs.Empty);
                break;

            case PubSubMessageType.Reconnect:
                HandleReconnect();
                break;

            case PubSubMessageType.Timeout:
                Timeout?.Invoke(this, (TimeoutMessageEventArgs)msg);
                break;

            case PubSubMessageType.Ban:
                Ban?.Invoke(this, (BanMessageEventArgs)msg);
                break;

            case PubSubMessageType.Unban:
                Unban?.Invoke(this, (UnbanMessageEventArgs)msg);
                break;

            case PubSubMessageType.Host:
                Host?.Invoke(this, (HostMessageEventArgs)msg);
                break;

            case PubSubMessageType.Bits:
                Bits?.Invoke(this, (BitsMessageEventArgs)msg);
                break;

            case PubSubMessageType.StreamStart:
                StreamStart?.Invoke(this, (StreamStartMessageEventArgs)msg);
                break;

            case PubSubMessageType.StreamStop:
                StreamStop?.Invoke(this, (StreamStopMessageEventArgs)msg);
                break;

            case PubSubMessageType.ViewerCount:
                ViewerCount?.Invoke(this, (ViewerCountMessageEventArgs)msg);
                break;

            default:
                Error?.Invoke(this, new ExceptionEventArgs(new ArgumentOutOfRangeException()));
                break;
            }
        }
예제 #3
0
 /// <summary>
 /// Called when a message was received that did not have a handler
 /// associated with it's command.
 /// </summary>
 /// <param name="msg">the message received.</param>
 protected virtual void OnUnknown(TmiMessage msg)
 {
     Unknown?.Invoke(this, new UnknownMessageEventArgs(msg));
 }