예제 #1
0
    public static void ListGameObjects(CUDLR.RequestContext context)
    {
        string json = "[";

        UnityEngine.Object[] objects = UnityEngine.Object.FindObjectsOfType(typeof(GameObject));
        foreach (UnityEngine.Object obj in objects)
        {
            // FIXME object names need to be escaped.. use minijson or similar
            json += string.Format("\"{0}\", ", obj.name);
        }
        json = json.TrimEnd(new char[] { ',', ' ' }) + "]";

        context.Response.WriteString(json, "application/json");
    }
예제 #2
0
        public static void Complete(RequestContext context)
        {
            string partialCommand = context.Request.QueryString.Get("command");

              string found = null;
              if (partialCommand != null)
            found = Console.Complete(partialCommand);

              context.Response.WriteString(found);
        }
예제 #3
0
        public static void Run(RequestContext context)
        {
            string command = context.Request.QueryString.Get("command");
              if (!string.IsNullOrEmpty(command))
            Console.Run(command);

              context.Response.StatusCode = (int)HttpStatusCode.OK;
              context.Response.StatusDescription = "OK";
        }
예제 #4
0
 public static void Output(RequestContext context)
 {
     context.Response.WriteString(Console.Output());
 }
예제 #5
0
        public static void History(RequestContext context)
        {
            string index = context.Request.QueryString.Get("index");

              string previous = null;
              if (!string.IsNullOrEmpty(index))
            previous = Console.PreviousCommand(System.Int32.Parse(index));

              context.Response.WriteString(previous);
        }
예제 #6
0
        void HandleRequest(RequestContext context)
        {
            try {
            bool handled = false;

            for (; context.currentRoute < registeredRoutes.Count; ++context.currentRoute) {
              RouteAttribute route = registeredRoutes[context.currentRoute];
              Match match = route.m_route.Match(context.path);
              if (!match.Success)
            continue;

              if (!route.m_methods.IsMatch(context.Request.HttpMethod))
            continue;

              // Upgrade to main thread if necessary
              if (route.m_runOnMainThread && Thread.CurrentThread != mainThread) {
            lock (mainRequests) {
              mainRequests.Enqueue(context);
            }
            return;
              }

              context.match = match;
              route.m_callback(context);
              handled = !context.pass;
              if (handled)
            break;
            }

            if (!handled) {
              context.Response.StatusCode = (int)HttpStatusCode.NotFound;
              context.Response.StatusDescription = "Not Found";
            }
              }
              catch (Exception exception) {
            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            context.Response.StatusDescription = string.Format("Fatal error:\n{0}", exception);

            Debug.LogException(exception);
              }

              context.Response.OutputStream.Close();
        }
예제 #7
0
        void ListenerCallback(IAsyncResult result)
        {
            RequestContext context = new RequestContext(listener.EndGetContext(result));

              HandleRequest(context);

              listener.BeginGetContext(new AsyncCallback(ListenerCallback), null);
        }
예제 #8
0
        static void FindFileType(RequestContext context, bool download, out string path, out string type)
        {
            path = Path.Combine(fileRoot, context.match.Groups[1].Value);

              string ext = Path.GetExtension(path).ToLower().TrimStart(new char[] {'.'});
              if (download || !fileTypes.TryGetValue(ext, out type))
            type = "application/octet-stream";
        }
예제 #9
0
        static void WWWFileHandler(RequestContext context, bool download)
        {
            string path, type;
              FindFileType(context, download, out path, out type);

              WWW req = new WWW(path);
              while (!req.isDone) {
            Thread.Sleep(0);
              }

              if (string.IsNullOrEmpty(req.error)) {
            context.Response.ContentType = type;
            if (download)
              context.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}", Path.GetFileName(path)));

            context.Response.WriteBytes(req.bytes);
            return;
              }

              if (req.error.StartsWith("Couldn't open file")) {
            context.pass = true;
              }
              else {
            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            context.Response.StatusDescription = string.Format("Fatal error:\n{0}", req.error);
              }
        }
예제 #10
0
        static void FileHandler(RequestContext context, bool download)
        {
            string path, type;
              FindFileType(context, download, out path, out type);

              if (File.Exists(path)) {
            context.Response.WriteFile(path, type, download);
              }
              else {
            context.pass = true;
              }
        }
예제 #11
0
 public static void Run(RequestContext context)
 {
     string command = Uri.UnescapeDataString(context.Request.QueryString.Get("command"));
     if (!string.IsNullOrEmpty(command))
         Console.Run(context, command);
 }
예제 #12
0
 public static void Output(RequestContext context)
 {
     context.Response.WriteString(Console.Output());
 }
예제 #13
0
 public static void Log(string str, RequestContext context)
 {
     Log(str);
     context.Response.StatusCode = (int)HttpStatusCode.OK;
     context.Response.StatusDescription = "OK";
 }
예제 #14
0
파일: Server.cs 프로젝트: mrubin/CUDLR
        void ListenerCallback(IAsyncResult result)
        {
            RequestContext context = new RequestContext(listener.EndGetContext(result));

              HandleRequest(context);

              if (listener.IsListening) {
            listener.BeginGetContext(ListenerCallback, null);
              }
        }