Пример #1
0
    //commands which don't require a nickname like .help, .time, .uptime, etc...
    bool IsCommand(string message, ECommands command)
    {
        if (message == Commands[(int)command])
        {
            return(true);
        }

        return(false);
    }
 public CProtocolMessage(byte ID, ECommands cmd, List<Byte> data)
 {
     this.ID = ID;
       this.Cmd = cmd;
       if (data == null)
     data = new List<byte>();
       this.Data = data;
       this.DataLength = (byte)data.Count;
       CalculateCrc();
 }
Пример #3
0
    //commands which contain a nickname like .quote newt, .seen newt, .burn newt, etc..
    bool IsCommand(string message, ECommands command, out string output_Nickname)
    {
        //splits the message into a array of words where delimiter is a space
        //and checks if the first word is a command
        //if true,
        //returns all other words combined into a string
        //for example - .seen some thing
        //here there are 3 words separated by space - ".seen", "some" and "thing".
        //since the word[0] here is ".seen" i.e a command, this function will set output_Nickname to "some" and "thing" combined into a string with a space in between and will return true

        output_Nickname = "";

        char[]   DelimeterChars = { ' ' };
        string[] words          = message.Split(DelimeterChars);

        //if the first word is a command
        if (words[0] == Commands[(int)command])
        {
            //to support space in between nicknames like ".quote The Comet"
            if (words.Length > 2)
            {
                //here int i = 1 cause we don't want to include first word (i.e a command) into output_Nickname
                for (int i = 1; i < words.Length; ++i)
                {
                    //add space between each word
                    output_Nickname += words[i];

                    //don't add a space at the end
                    if (i != words.Length - 1)
                    {
                        output_Nickname += " ";
                    }
                }
            }
            //incase there's no space in the nickname like ".quote newt"
            else if (words.Length == 2)
            {
                output_Nickname = words[1];
            }

            return(true);
        }

        return(false);
    }
Пример #4
0
    public void ResolveCommand(ECommands commands, params object[] list)
    {
        switch(commands) {
            case ECommands.Move: {
                if(Selected) {
                    TargetLocation = (Vector2)list[0];
                    IsMoving = true;
                }
                break;
            }
            case ECommands.Select: {
                Selected = (bool)list[0];
                break;
            }

            case ECommands.Link: {
                ICreature component = (ICreature)list[0];
                if(!(Tail.Contains(component))) {
                    Tail.Add(component);
                    component.ResolveCommand(ECommands.Link, this);
                }
                if(Tail.Count > 5) {
                    Game.Instance.CreateBonus();
                }
                break;
            }
            case ECommands.BreakLink: {
                foreach(ICreature pony in Tail) {
                    pony.ResolveCommand(ECommands.BreakLink);
                }
                Tail.Clear();
                //ICreature component = (ICreature)list[0];
                //if(Tail.Contains(component)) {
                //	Tail.Remove(component);
                //	component.ResolveCommand(ECommand.Unlink);
                //}
                break;
            }
        }
    }
Пример #5
0
 public void ResolveCommand(ECommands commands, params object[] list)
 {
     switch(commands) {
         case ECommands.Link: {
             FollowTarget = ((Dog)list[0]).transform;
             Head = (ICreature)list[0];
             break;
         }
         case ECommands.Select: {
             Debug.Log("Cant select pony");
             break;
         }
         case ECommands.BreakLink: {
             FollowTarget = null;
             Head = null;
             if(Game.Instance != null) { // spike for pass test (BreakLinkTest)
                 Game.Instance.CollectPony(this);
                 Destroy(gameObject);
             }
             break;
         }
     }
 }
Пример #6
0
 public void ResolveCommand(ECommands commands, params object[] list)
 {
 }
Пример #7
0
        void FindCommandParams(ILogger inLoger)
        {
            if (_tokens.Length == 0)
            {
                return;
            }

            if (_tokens[0].TokenType != CTokenFinder.COMMAND_PREFIX)
            {
                return;
            }

            if (_tokens.Length < 2)
            {
                inLoger.LogError(EErrorCode.UnknownCommand, this);
                return;
            }

            ECommands[] coms = (ECommands[])Enum.GetValues(typeof(ECommands));
            for (int i = 0; i < coms.Length && _command == ECommands.None; ++i)
            {
                if (string.Equals(coms[i].ToString(), _tokens[1].Text, StringComparison.InvariantCultureIgnoreCase))
                {
                    _command = coms[i];
                }
            }

            if (_command == ECommands.None)
            {
                inLoger.LogError(EErrorCode.UnknownCommandName, this);
                return;
            }


            int curr_index = 2;

            while (curr_index < _tokens.Length)
            {
                bool triplet = false;
                if (_tokens.Length - curr_index >= 3)
                {
                    int colon_index = curr_index + 1;
                    triplet = _tokens[colon_index].TokenType == ETokenType.Colon;
                    if (triplet)
                    {
                        if (_command_params.Add(_tokens[curr_index].Text, _tokens[curr_index + 2].Text))
                        {
                            curr_index += 3;
                        }
                        else
                        {
                            inLoger.LogError(EErrorCode.DublicateCommandParam, this);
                            return;
                        }
                    }
                }

                if (!triplet)
                {
                    if (_command_params.Add(_tokens[curr_index].Text, string.Empty))
                    {
                        curr_index += 1;
                    }
                    else
                    {
                        inLoger.LogError(EErrorCode.DublicateCommandParam, this);
                        return;
                    }
                }
            }
        }
        public bool SendAndRead(ECommands cmd, List<Byte> data, ECommands matchCmd, out List<Byte> matchData)
        {
            var txMsg = new CProtocolMessage(mGetNextTxPacketId(), cmd, data);

              byte expectedResponsePacketId;
              //The machine always responds with a packet Ok with id 255 upon reset
              if (cmd == ECommands.RESET_COMMAND)
              {
            mCurrentTxPacketId = 255;
            expectedResponsePacketId = 255;
              }
              else
            expectedResponsePacketId = mCurrentTxPacketId;

              for (int i = 1; i <= 10; i++)
              {
            mSendDo(txMsg);
            CProtocolMessage rxMsg = Read();
            byte correctCRC;
            if (rxMsg.ID != expectedResponsePacketId)
              Logging.Log.LogError("Received invalid packet ID, desired " + expectedResponsePacketId + ", received " + rxMsg.ID);
            else if (!rxMsg.VerifyCRC(out correctCRC))
              Logging.Log.LogError("Received invalid packet CRC, desired " + correctCRC + ", received " + rxMsg.CRC);
            else if (rxMsg.Cmd != matchCmd)
              Logging.Log.LogError("Received invalid response command, desired " + matchCmd.ToString() + ", received " + rxMsg.Cmd.ToString());
            else
            {
              matchData = rxMsg.Data;
              return true;
            }
              }

              matchData = null;
              return false;
        }
 public void SendAndMatch(ECommands cmd, List<Byte> data, ECommands matchCmd)
 {
     List<Byte> readData;
       SendAndRead(cmd, data, matchCmd, out readData);
 }
 //TODO Inline on callers
 public void Send(ECommands cmd, List<Byte> data)
 {
     SendAndMatch(cmd, data, ECommands.OK_COMMAND);
 }
 public void Send(ECommands cmd)
 {
     Send(cmd, null);
 }
Пример #12
0
        private static (ECommands commandType, BaseCommand command) InstanciateCommand(ECommands command)
        {
            switch (command)
            {
            case ECommands.InitializeRepository: return(ECommands.InitializeRepository, new InitializeCommand());

            case ECommands.Indexation: return(ECommands.Indexation, new IndexationCommand());

            case ECommands.Save: return(ECommands.Save, new SaveCommand());

            case ECommands.Users: return(ECommands.Users, new UserCommand());

            case ECommands.AllUsers: return(ECommands.AllUsers, new AllUsersCommand());

            case ECommands.Set: return(ECommands.Set, new SetCommand());

            case ECommands.SetMultithreading: return(ECommands.SetMultithreading, new SetMultithreadingCommand());

            case ECommands.Get: return(ECommands.Get, new GetCommand());

            case ECommands.GetMultithreading: return(ECommands.GetMultithreading, new GetMultithreadingCommand());

            case ECommands.Promote: return(ECommands.Promote, new PromoteCommand());

            case ECommands.ConnectServer: return(ECommands.ConnectServer, new ConnectServerCommand());

            case ECommands.Quit: return(ECommands.Quit, new QuitCommand());

            default: throw new NotImplementedException();
            }
            throw new NotImplementedException();
        }