Exemple #1
0
        public static void SendInput(string Line)
        {
            // Ignore empty
            Line = Line.Trim();
            if (Line.Length == 0 || Line.StartsWith("//"))
            {
                return;
            }

            Color = Color.White;
            if (Echo)
            {
                WriteLine("> {0}", Line);
            }
            string[] ArgvLine = ParseLine(Line).ToArray();

            foreach (var Argv in ArgvLine.Split(";"))
            {
                ConVar Var;

                for (int i = 0; i < Argv.Length; i++)
                {
                    if (Argv[i].StartsWith("$") && ConVar.TryFind(Argv[i].Substring(1), out Var))
                    {
                        Argv[i] = Var.StringValue;
                    }
                }

                if (Argv.Length == 1 && Aliases.ContainsKey(Argv[0]))
                {
                    bool OldEcho = Echo;
                    Echo = false;
                    SendInput(Aliases[Argv[0]]);
                    Echo = OldEcho;
                    return;
                }

                try {
                    if (Argv.Length == 2 && (Argv[0] == "+" || Argv[0] == "-"))
                    {
                        if (ConVar.TryFind(Argv[1], out Var))
                        {
                            if (Var is ConVar <int> )
                            {
                                ((ConVar <int>)Var).Value = Argv[0] == "+" ? 1 : 0;
                            }
                            else if (Var is ConVar <bool> )
                            {
                                ((ConVar <bool>)Var).Value = Argv[0] == "+" ? true : false;
                            }
                            else
                            {
                                Error("Unknown variable type '{0}'", Var.ObjectValue.GetType().Name);
                            }
                        }
                        else
                        {
                            Error("Cannot toggle non existing variable '{0}'", Argv[1]);
                        }
                    }
                    else if ((Argv.Length == 1 || Argv.Length == 2) && ConVar.TryFind(Argv[0], out Var))
                    {
                        if (Argv.Length == 2)
                        {
                            Var.StringValue = Argv[1];
                        }

                        if (Echo)
                        {
                            WriteLine(Var);
                        }
                    }
                    else if (Argv.Length == 3 && Argv[1] == "=" && ConVar.TryFind(Argv[0], out Var))
                    {
                        Var.StringValue = Argv[2];

                        if (Echo && Argv.Length != 3)
                        {
                            WriteLine(Var);
                        }
                    }
                    else if (Argv.Length > 0 && ConCmd.TryFind(Argv[0], out ConCmd Cmd))
                    {
                        Cmd.Command(Argv);
                    }
                    else
                    {
                        Error("Unknown command/variable '{0}'", Argv[0]);
                    }
                } catch (Exception E) {
                    Engine.LogFatal(E);

                    Error("{0}: {1}", E.GetType().Name, E.Message);
                }
            }
        }
Exemple #2
0
        public static void ReceiveCmd(object obj)
        {
            Socket s = obj as Socket;

            byte[] buffer = null;
            while (true)
            {
                try
                {
                    buffer = new byte[200];
                    s.Receive(buffer);
                }
                catch (ArgumentNullException)
                {
                    //MessageBox.Show("发送的东西为空");
                    // s.Dispose();
                    //InfoHandle.threadDisk.Abort();
                    return;
                }
                catch (SocketException)
                {
                    //MessageBox.Show("访问套接字失败");
                    return;
                }
                catch (ObjectDisposedException)
                {
                    Debug.WriteLine("连接已断开");
                    //MessageBox.Show("连接已断开");
                    //DisConnect();
                    //Cmd.OnStartUp();
                    return;
                }
                string info = Encoding.UTF8.GetString(buffer);
                info = Msg.HandleRcvMsg(info);
                //考虑是否有#
                try
                {
                    if (info.Contains("XiYou#"))
                    {
                        HandleRcvMsg(ref info);
                        Debug.WriteLine("SocketCmd接收的信息:" + info);
                        Command command = JsonConvert.DeserializeObject <Command>(info);
                        if (command.Flag == "1")
                        {
                            HandleModel handle = JsonConvert.DeserializeObject <HandleModel>(command.Msg);
                            Cmd.Command(handle);
                        }
                        else if (command.Flag == "2")
                        {
                            //json反序列为类
                            DiskFolder folder = JsonConvert.DeserializeObject <DiskFolder>(command.Msg);
                            DiskHandle(folder);
                        }
                        else if (command.Flag == "3")
                        {
                            string[] offset = Regex.Split(command.Msg, ",");
                            if (offset.Length >= 2 && offset.Length < 5)
                            {
                                var sgl1 = new Signal1();
                                sgl1.x    = Convert.ToDouble(offset[0]);
                                sgl1.y    = Convert.ToDouble(offset[1]);
                                sgl1.mode = Msg.HandleRcvMsg(offset[2]);
                                Signal1.DoMouseEvent(sgl1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }