Beispiel #1
0
    private void OnBeginLoading(System.Object sender, Awesomium.Mono.BeginLoadingEventArgs args)
    {
        if (args.Url.Length < 1)
        {
            return;
        }

        if (IsBlackListedLoad(args.Url))
        {
            webView.GoBack();
            return;
        }

        if (HandleRedirectLoad(args.Url))
        {
            return;
        }

        SetToLoadingTexture();
        if (args.Url != lastURL)
        {
            lastURL = args.Url;
            RaiseLoadBeginEvent(args.Url);
        }
        else
        {
            VDebug.Log("skipping url: " + args.Url);
        }
        goingBack    = false;
        goingForward = false;
    }
Beispiel #2
0
    public string FindByColumnValue(string c, string v)
    {
        string json = "{\"" + c + "\":\"" + v + "\"}";

        VDebug.Log("FindByColumnValue json: " + json);
        return(FindByColumnValue(json));
    }
Beispiel #3
0
 public void RefreshWebView()
 {
     if (CheckWebView() && !webView.IsLoadingPage)
     {
         VDebug.Log("Refresh server data");
         webView.Reload();
     }
 }
Beispiel #4
0
 public bool ExecuteJavascript(string cmd)
 {
     if (!loading && htmlPanel != null)
     {
         VDebug.Log("HTMLGuiLayer - ExecuteJavascript: " + cmd);
         htmlPanel.browserTexture.ExecuteJavaScript(cmd);
     }
     return(!loading);
 }
Beispiel #5
0
    public JSValue ExecuteJavascriptWithValue(string cmd)
    {
        JSValue ret = null;

        if (!loading && htmlPanel != null)
        {
            VDebug.Log("HTMLGuiLayer - ExecuteJavascriptWithValue: " + cmd);
            ret = htmlPanel.browserTexture.ExecuteJavaScriptWithResult(cmd);
        }
        return(ret);
    }
Beispiel #6
0
    private bool CheckWebView()
    {
        bool ret = WebCore.IsRunning && (webView != null) && webView.IsEnabled;

        if (!ret && displayWebViewErrors)
        {
            VDebug.Log("Webview Failed!!\nWebCore.IsRunning: " + WebCore.IsRunning);
            if (webView != null)
            {
                VDebug.Log("webView: " + webView.ToString());
                VDebug.Log("webView.IsEnabled: " + webView.IsEnabled.ToString());
            }
            displayWebViewErrors = WebCore.IsRunning;
        }
        return(ret);
    }
Beispiel #7
0
    private void OnDestroy()
    {
        allBrowserTextures.Remove(id);
        if (CheckWebView())
        {
            // Free the pinned array handle.
            PixelsHandle.Free();

            if (WebCore.IsRunning)
            {
                WebViewManager.Inst.CloseWebView(webView);
                webView = null;

                VDebug.Log("Destroyed View");
            }
        }
    }
Beispiel #8
0
 public void OnPublicMessage(string message, User sender, Room room)
 {
     // We use lock here to ensure cross-thread safety on the messages collection
     lock (messagesLocker) {
         //checking who the sender name is
         if (sender.IsItMe)
         {
             lastmsg = "me: " + message;
         }
         else
         {
             lastmsg = sender.Name + ": " + message;
             SoundManager.Inst.PlayPM();
         }
         messages.Add(lastmsg);
         GameGUI.Inst.UpdateChatGUI(getChatBuffer());
         GameGUI.Inst.guiLayer.SendGuiLayerChat(message, sender.Name, sender.Id, room != null && CommunicationManager.IsPrivateRoom(room.Name));
     }
     VDebug.Log("User " + sender.Name + " said: " + message);
 }
Beispiel #9
0
    public void OnPrivateMessage(BaseEvent evt)
    {
        string     message   = (string)evt.Params["message"];
        User       sender    = (User)evt.Params["sender"];
        ISFSObject recipient = (SFSObject)evt.Params["data"];

        if (sender.IsItMe)
        {
            lastmsg = "PM to " + recipient.GetUtfString("name") + " : " + message;
        }
        else
        {
            lastmsg = "PM from " + sender.Name + ": " + message;
            SoundManager.Inst.PlayPM();
        }
        messages.Add(lastmsg);
        GameGUI.Inst.UpdateChatGUI(getChatBuffer());
        GameGUI.Inst.guiLayer.SendGuiLayerChat(message, sender.Name, sender.Id, false, true, recipient.GetUtfString("name"));

        VDebug.Log("PM: " + message + ", from: " + sender.Name);
    }
Beispiel #10
0
    private void SpawnRemotePlayer(SFSUser user, string room = "")
    {
        VDebug.Log("Spawning user: "******" room: " + room);

        // New client just started transmitting - lets create remote player
        PlayerInit pInit = InitPlayerVariablesFromUserVariables(user.GetVariables());

        pInit.displayName = (string.IsNullOrEmpty(pInit.displayName)) ? user.Name : pInit.displayName;


        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null)
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
            players.Remove(user.Id);
            if (user.Name == GetLocalPlayer().SFSName)
            {
                Debug.LogError("Caught someone logging in with my name, logging out");
                CommunicationManager.Inst.LogOut();
                return;
            }
        }

        if (pInit.ptype != PlayerType.STEALTH && roomEntrySoundFlag)
        {
            SoundManager.Inst.PlayEnter();
        }

        Player remotePlayer = CreateRemotePlayer(user, pInit.modelIndex, pInit.Pos, pInit.Rot, pInit.optionsStr, pInit.parseID, pInit.displayName, pInit.teamID, pInit.ptype, pInit.sit);

        if (CommunicationManager.IsPrivateRoom(room))
        {
            GameGUI.Inst.ExecuteJavascriptOnGui(remotePlayer.GetUserEnterPrivateRoomJSCmd(room));
        }
    }
        public static void OnPostprocessBuild(BuildTarget target, string path)
        {
            if (target != BuildTarget.WebGL)
            {
                return;
            }

            // Delete existing 'screen.html' (previous build)
            if (File.Exists(path + "/screen.html"))
            {
                File.Delete(path + "/screen.html");
            }

            // Rename 'index.html' to 'screen.hmtl'
            File.Move(path + "/index.html", path + "/screen.html");

            #if UNITY_5_6_OR_NEWER
            // Delete existing 'game.json' (previous build)
            if (File.Exists(path + "/Build/game.json"))
            {
                File.Delete(path + "/Build/game.json");
            }

            // Rename '<projectName>.json' to 'game.json'
            File.Move(
                String.Format("{0:G}/Build/{1:G}.json", path, Path.GetFileName(path)),
                path + "/Build/game.json"
                );
            #endif

            // Save build path in preferences
            EditorPrefs.SetString("BuildPath", path);
            Config.BuildPath = path;

            VDebug.Log("[Volplane] Completed build!");
        }
Beispiel #12
0
    // Use this for initialization
    void Start()
    {
        htmlPanel        = this.gameObject.AddComponent(typeof(HTMLPanelGUI)) as HTMLPanelGUI;
        htmlPanel.width  = Screen.width;
        htmlPanel.height = Screen.height;
        htmlPanel.RegisterNotificationCallback("InitComplete", delegate(JSValue[] args)
        {
            VDebug.LogError("Loading complete: " + (DateTime.Now - startLoadHTMLTime).TotalSeconds);
            if (loading)
            {
                Debug.LogError("JavaScript Execution started BEFORE awesomium finished loading page!!");
                loading = false;
            }
            if (!skipLogin && GameManager.Inst.LevelLoaded == GameManager.Level.CONNECT)
            {
                System.Version currClientVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                Debug.LogError("Client version: " + currClientVersion.ToString() + " req: " + CommunicationManager.clientVersionRequirement);
                if (CommunicationManager.clientVersionRequirement == "")
                {
                    // no version requirement specified, hand control to the guilayer.
                    WebHelper.ClearCache = true;
                    HandleClientVersion(currClientVersion.ToString());
                    return;
                }
                System.Version clientReq = new System.Version(CommunicationManager.clientVersionRequirement);
                if (currClientVersion >= clientReq)
                {
                    AttemptLogin();
                }
                else
                {
                    ExecuteJavascriptWithValue(SetGUIVersionJSCmd() + SetBuildTypeCmd() + SetConfigCmd() + "showUpdateDialog();");
                }
            }
            else
            {
                Debug.LogError((skipLogin) ? "Login screen skipped" : "GUI Layer has been reloaded in another scene!");
                skipLogin = false;
            }
        });
        htmlPanel.RegisterNotificationCallback("Authentication_Success", delegate(JSValue[] args)
        {
            GameGUI.Inst.fadeOut = true;

            loginArgs = args[1].ToString();
            loggingIn = true;
        });
        htmlPanel.RegisterNotificationCallback("MouseUp_MouseClick", delegate(JSValue[] args) {
            string json = args[1].ToString();
            VDebug.Log("mouseup fields: " + json);
            GameObject hitObject = MouseHelpers.GetCurrentGameObjectHit();
            if (hitObject != null)
            {
                if (GameManager.Inst.LocalPlayer.gameObject == hitObject)
                {
                    string cmd = "OnLocalPlayerClick(" + json + ");";
                    ExecuteJavascript(cmd);
                }
                else
                {
                    PlayerController playerController = hitObject.GetComponent <PlayerController>();
                    if (playerController != null)
                    {
                        Player p   = playerController.playerScript;
                        string cmd = "OnPlayerClick(" + p.Id + ", " + p.Name + ", " + json + ");";
                        ExecuteJavascript(cmd);
                    }

                    WebPanel webPanel = hitObject.GetComponent <WebPanel>();
                    if (webPanel != null)
                    {
                        string cmd = "OnWebPanelClick(" + webPanel.browserTexture.id + ", " + json + ");";
                        ExecuteJavascript(cmd);
                    }


                    //string go = hitObject.name;// +hitObject.GetInstanceID();
                    //Debug.Log("We clicked something: " + go);
                    //string cmd = "OnUnityObjectClick('" + go + "', " + json + ");";
                    ////Debug.Log(cmd);
                    //ExecuteJavaScript(cmd);
                }
            }
        });
        htmlPanel.RegisterNotificationCallback("Out_UnityDebugLog", delegate(JSValue[] args) {
            string json           = args[1].ToString();
            JSONObject jsonObject = JSONObject.Parse(json);
            string msg            = jsonObject.GetString("msg");
            Debug.Log("Out_UnitDebugLog: " + msg);
        });
        htmlPanel.RegisterNotificationCallback("Clicked_QuitButton", delegate(JSValue[] args)
        {
            Application.Quit();
        });
        htmlPanel.RegisterNotificationCallback("Closed_DialogWindow", delegate(JSValue[] args)
        {
            AnnouncementManager.Inst.AnnouncementClosed();
        });
        htmlPanel.RegisterNotificationCallback("Clicked_AvatarButton", delegate(JSValue[] args)
        {
            GameManager.Inst.LoadLevel(GameManager.Level.AVATARSELECT);
        });
        htmlPanel.RegisterNotificationCallback("Clicked_ToggleVoice", delegate(JSValue[] args)
        {
            VoiceManager.Inst.ToggleToTalk = !VoiceManager.Inst.ToggleToTalk;
        });
        htmlPanel.RegisterNotificationCallback("VoicePush", delegate(JSValue[] args)
        {
            VoiceManager.Inst.PushToTalkButtonDown = args[1].ToBoolean();
        });
        htmlPanel.RegisterNotificationCallback("Clicked_RefreshAll", delegate(JSValue[] args)
        {
            if (GameManager.Inst.LevelLoaded == GameManager.Level.BIZSIM)
            {
                BizSimManager.Inst.ReloadAll();
            }
        });
        htmlPanel.RegisterNotificationCallback("Update_UserList", delegate(JSValue[] args)
        {
            GameGUI.Inst.userListMgr.RebuildHTMLUserList();
        });
        htmlPanel.RegisterNotificationCallback("Update_Timer", delegate(JSValue[] args)
        {
            UpdateTimer();
        });
        htmlPanel.RegisterNotificationCallback("Update_VoiceToggle", delegate(JSValue[] args)
        {
            // ask unity if the voice is toggled on or off
            InitVoiceToggle();
        });
        htmlPanel.RegisterNotificationCallback("Play_ButtonClickSound", delegate(JSValue[] args)
        {
            SoundManager.Inst.PlayClick();
        });
        htmlPanel.RegisterNotificationCallback("Clicked_LogoutButton", delegate(JSValue[] args)
        {
            CommunicationManager.Inst.LogOut();
        });


        // Tooltips
        htmlPanel.RegisterNotificationCallback("Set_Tooltip", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to change fixed tooltip, but didn't find an argument.");
                return;
            }
            GameGUI.Inst.SetFixedTooltip(args[1].ToString());
        });
        htmlPanel.RegisterNotificationCallback("Clear_Tooltip", delegate(JSValue[] args)
        {
            GameGUI.Inst.ClearFixedTooltip();
            GameGUI.Inst.tooltipAvoidRect = new Rect(0, 0, 0, 0); // clear avoidance rectangle
        });
        htmlPanel.RegisterNotificationCallback("Set_TooltipAvoidRect", delegate(JSValue[] args)
        {
            if (args.Length <= 4)
            {
                Debug.LogError("attempting to change fixed tooltip avoidance rectangle, but didn't find enough arguments.");
                return;
            }
            GameGUI.Inst.tooltipAvoidRect = new Rect(int.Parse(args[1].ToString()), int.Parse(args[2].ToString()), int.Parse(args[3].ToString()), int.Parse(args[4].ToString()));
        });

        // Microphone selection menu
        htmlPanel.RegisterNotificationCallback("Open_Mic_Menu", delegate(JSValue[] args)
        {
            VoiceManager.Instance.micSelectMenuOpen = true;
        });
        htmlPanel.RegisterNotificationCallback("Close_Mic_Menu", delegate(JSValue[] args)
        {
            VoiceManager.Instance.micSelectMenuOpen = false;
        });
        htmlPanel.RegisterNotificationCallback("Toggle_Mic_Menu", delegate(JSValue[] args)
        {
            VoiceManager.Instance.micSelectMenuOpen = !VoiceManager.Instance.micSelectMenuOpen;
        });

        // Seed console with text and move cursor to the front of the input.
        htmlPanel.RegisterNotificationCallback("Seed_Console", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                GameGUI.Inst.consoleGui.SeedConsole("");
                return;
            }
            GameGUI.Inst.consoleGui.SeedConsole(args[1].ToString());
        });

        htmlPanel.RegisterNotificationCallback("Issue_ConsoleCmd", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to issue console command, but didn't find an argument.");
                return;
            }
            ConsoleInterpreter.Inst.ProcCommand(args[1].ToString());
        });
        htmlPanel.RegisterNotificationCallback("Issue_FacConsoleCmd", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to issue console command, but didn't find an argument.");
                return;
            }
            ConsoleInterpreter.Inst.ProcCommand(args[1].ToString(), PlayerType.LEADER);
        });
        htmlPanel.RegisterNotificationCallback("Write_ToConsole", delegate(JSValue[] args)
        {
            string msg = (args.Length <= 1) ? "" : args[1].ToString();
            GameGUI.Inst.WriteToConsoleLog(msg);
        });
        htmlPanel.RegisterNotificationCallback("Open_Browser", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("no url specified for Open_Browser command.");
            }
            OpenInExternalBrowser(args[1].ToString());
        });
        htmlPanel.RegisterNotificationCallback("Click_AvatarChangeCharacter", delegate(JSValue[] args)
        {
            if (args.Length < 2)
            {
                Debug.LogError("no url specified for Open_Browser command.");
                return;
            }
            int modelIdx;
            if (!int.TryParse(args[1].ToString(), out modelIdx))
            {
                Debug.LogError(args[1] + " not a valid int");
                return;
            }
            GameGUI.Inst.customizeAvatarGui.ChangeCharacter(modelIdx);
        });
        htmlPanel.RegisterNotificationCallback("Click_AvatarOption", delegate(JSValue[] args)
        {
            if (args.Length < 3)
            {
                Debug.LogError("Click_AvatarOption - not enough arguments: elementName, newIndex " + args.Length);
                return;
            }

            int optionIdx;
            if (!int.TryParse(args[2].ToString(), out optionIdx))
            {
                Debug.LogError(args[2] + " not a valid int");
                return;
            }
            GameGUI.Inst.customizeAvatarGui.ChangeElement(args[1].ToString(), optionIdx);
        });
        htmlPanel.RegisterNotificationCallback("Click_AvatarRotate", delegate(JSValue[] args)
        {
            if (args.Length < 3)
            {
                Debug.LogError("Click_AvatarRotate - not enough arguments: is_left, is_down");
                return;
            }

            GameGUI.Inst.customizeAvatarGui.HandleRotateBtn(args[1].ToBoolean());
            GameGUI.Inst.customizeAvatarGui.HandleRotateDown(args[2].ToBoolean());
        });
        htmlPanel.RegisterNotificationCallback("Click_AvatarDone", delegate(JSValue[] args)
        {
            bool save = true;
            if (args.Length > 1)
            {
                save = args[1].ToBoolean();
            }
            GameGUI.Inst.customizeAvatarGui.HandleDoneBtn(save);
        });
        htmlPanel.RegisterNotificationCallback("Confirm_Action", delegate(JSValue[] args)
        {
            string action = (args.Length > 1) ? args[1].ToString() : "";
            if (GameManager.Inst.LevelLoaded == GameManager.Level.BIZSIM)
            {
                BizSimManager.Inst.HandleAction(action);
            }
        });
        htmlPanel.RegisterNotificationCallback("Send_SFSRequest", delegate(JSValue[] args)
        {
            if (args.Length < 2)
            {
                Debug.LogError("Not enough arguments for Send_SFSRequest");
                return;
            }

            string msg        = (args.Length > 2) ? args[2].ToString() : "";
            ISFSObject msgObj = new SFSObject();
            msgObj.PutUtfString("msg", msg);
            ExtensionRequest request = new ExtensionRequest(args[1].ToString(), msgObj);
            CommunicationManager.SendMsg(request);
        });
        htmlPanel.RegisterNotificationCallback("Set_InputFocus", delegate(JSValue[] args)
        {
            if (args.Length < 2)
            {
                Debug.LogError("Set_InputFocus needs true/false argument");
                return;
            }
            hasInputFocus = args[1].ToString() == "true";
        });
        htmlPanel.RegisterNotificationCallback("Toggle_ClickOffElement", delegate(JSValue[] args)
        {
            if (args.Length < 2)
            {
                Debug.LogError("Toggle_ClickOffElement needs true/false argument");
                return;
            }

            clickOffElementOpen = args[1].ToString() == "true";
        });
        htmlPanel.RegisterNotificationCallback("Overlay_URL", delegate(JSValue[] args)
        {
            if (args.Length < 2)
            {
                Debug.LogError("Overlay_URL needs url");
                return;
            }
            string url = args[1].ToString();
            int width  = (args.Length > 2) ? args[2].ToInteger() : (int)(0.75f * Screen.width);
            int height = (args.Length > 3) ? args[3].ToInteger() : (int)(0.75f * Screen.height);

            GameManager.Inst.OverlayMgr.SetURL(url, width, height);
        });
        htmlPanel.RegisterNotificationCallback("Scale_PresentTool", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to scale present tool, but didn't find an argument.");
                return;
            }
            GameGUI.Inst.presentToolScale = (float)args[1].ToDouble();
        });
        htmlPanel.RegisterNotificationCallback("Set_GameGUIGutter", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to set game gui gutter, but didn't find an argument.");
                return;
            }
            GameGUI.Inst.gutter = args[1].ToInteger();
        });
        htmlPanel.RegisterNotificationCallback("Hide_PresentUI", delegate(JSValue[] args)
        {
            GameGUI.Inst.showPresentToolButtons = false;
        });
        htmlPanel.RegisterNotificationCallback("Open_FileDialog", delegate(JSValue[] args)
        {
            string file = NativePanels.OpenFileDialog(null);
            string cmd  = "handleOpenFile(\"" + file + "\");";
            ExecuteJavascript(cmd);
        });
        htmlPanel.RegisterNotificationCallback("Set_Clipboard", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to set clipboard, but didn't find an argument.");
                return;
            }
            ClipboardHelper.Clipboard = args[1].ToString();
        });
        htmlPanel.RegisterNotificationCallback("Set_GUIVisibility", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to set gui visibility, but didn't find an argument.");
                return;
            }
            GameGUI.Inst.VisibilityFlags = args[1].ToInteger();
        });
        htmlPanel.RegisterNotificationCallback("Update_TutorialCode", delegate(JSValue[] args)
        {
            if (args.Length <= 1)
            {
                Debug.LogError("attempting to update tutorial code, but didn't find an argument.");
                return;
            }
            CommunicationManager.CurrentUserProfile.UpdateTutorial(args[1].ToInteger());
        });



        htmlPanel.RegisterNotificationCallback("Request_AvatarOptions", SendGuiLayerAvatarOptions);
        htmlPanel.RegisterNotificationCallback("Request_GameIds", SendGuiLayerNumGames);
        htmlPanel.RegisterNotificationCallback("Request_TeamInfo", SendGuiLayerTeamInfo);
        htmlPanel.RegisterNotificationCallback("Request_MicInfo", SendGuiLayerMicInfo);
        htmlPanel.RegisterNotificationCallback("Request_TeacherClassInfo", SendGuiLayerTeamTeacherClass);
        htmlPanel.RegisterNotificationCallback("Request_PanelTitle", SendGuiLayerPanelTitle);
        htmlPanel.RegisterNotificationCallback("Request_PanelURL", SendGuiLayerPanelURL);
        htmlPanel.RegisterNotificationCallback("Request_PanelSelection", SendGuiLayerPanelSelection);
        htmlPanel.RegisterNotificationCallback("Request_GetClipboard", SendGuiLayerClipboard);
        htmlPanel.RegisterNotificationCallback("Request_GUIVisibility", SendGuiLayerGUIVisibility);
        htmlPanel.RegisterNotificationCallback("Request_PlayerInfo", SendGuiLayerPlayerInfo);
        htmlPanel.RegisterNotificationCallback("Request_WorkingDir", SendGuiLayerWorkingDir);
        htmlPanel.RegisterNotificationCallback("Request_ReplayUpdate", SendGuiLayerReplayPosInfo);
        htmlPanel.RegisterNotificationCallback("Request_TutorialCode", SendGuiLayerTutorialCode);
        htmlPanel.RegisterNotificationCallback("Request_HardwareInfo", SendGuiLayerHardwareInfo);

#if PATCHER_ENABLE
        //startingFile = GameManager.Inst.guipatcher.path + startingFile;
        Debug.LogError("HTMLGuiLayer - starting file: " + startingFile);
#endif
    }
        /// <summary>
        /// Volplane server procedure for processing the incoming request.
        /// Request for files: 'screen.html', and 'controller.html' are sent from the AirConsole simulator.
        /// </summary>
        /// <param name="context">HttpListener context.</param>
        protected override void ProcessRequest(HttpListenerContext context)
        {
            HttpListenerRequest request = context.Request;

            byte[] buffer;

            // If POST data is sent -> request coming from controller editor.
            if (!request.HasEntityBody)
            {
                string filePath;
                string serverPath = request.Url.LocalPath;

                if (serverPath.StartsWith("/build/"))
                {
                    // Local build path
                    serverPath = serverPath.Replace("/build/", "/");
                    filePath   = String.Format(
                        "{0:G}{1:G}",
                        Config.BuildPath,
                        serverPath
                        );
                }
                else if (serverPath.StartsWith("/volplane/"))
                {
                    // Local web server path
                    serverPath = serverPath.Replace("/volplane/", "/");
                    filePath   = localPath + Config.WebServerPath + serverPath;
                }
                else
                {
                    // WebGL template path
                    filePath = localPath + Config.WebTemplatePath + serverPath;

                    if (String.Equals(Path.GetFileName(filePath), "screen.html"))
                    {
                        filePath = filePath.Replace("screen.html", "index.html");
                    }
                }

                filePath = pathSeparatorReg.Replace(filePath, Path.DirectorySeparatorChar.ToString());
                filePath = Uri.UnescapeDataString(filePath);

                if (File.Exists(filePath))
                {
                    buffer = File.ReadAllBytes(filePath);

                    context.Response.StatusCode      = (int)HttpStatusCode.OK;
                    context.Response.ContentType     = ReturnMIMEType(Path.GetExtension(filePath));
                    context.Response.ContentLength64 = buffer.Length;
                }
                else
                {
                    // File not found
                    buffer = System.Text.Encoding.UTF8.GetBytes("<html><head><title>404 Not Found.</title></head><body><h1>Error 404 - Not Found.</h1></body></html>");

                    context.Response.StatusCode      = (int)HttpStatusCode.NotFound;
                    context.Response.ContentType     = ReturnMIMEType("text/html");
                    context.Response.ContentLength64 = buffer.Length;
                }

                using (Stream s = context.Response.OutputStream)
                {
                    s.Write(buffer, 0, buffer.Length);
                }
            }
            else
            {
                // Saving controller data
                buffer = System.Text.Encoding.UTF8.GetBytes("saved");

                string controllerName = null;

                try
                {
                    controllerName = FileManager.WriteJSON(request.InputStream, String.Format("{0:G}{1:G}/data/controller", localPath, Config.WebServerPath));

                    // If the controller is currently used
                    if (Config.SelectedController == controllerName)
                    {
                        // Copy selected controller data into WebGL template
                        File.Copy(String.Format("{0:G}{1:G}/data/controller/{2:G}.json", localPath, Config.WebServerPath, controllerName),
                                  String.Format("{0:G}{1:G}/controller.json", localPath, Config.WebTemplatePath),
                                  true);
                    }

                    if (Config.DebugLog == (int)DebugState.All)
                    {
                        VDebug.Log("[Volplane (File Manager)] Controller saved!");
                    }
                }
                catch (Exception e)
                {
                    buffer = System.Text.Encoding.UTF8.GetBytes(
                        String.Format("Could not write data to path: {0:G}{1:G}/data/controller", localPath, Config.WebServerPath)
                        );

                    if (Config.DebugLog == (int)DebugState.All)
                    {
                        VDebug.LogErrorFormat("[Volplane (File Manager)] Unable to write file to: '{0:G}{1:G}/data/controller'.", localPath, Config.WebServerPath);
                        VDebug.LogException(e);
                    }
                }
                finally
                {
                    // Response
                    context.Response.StatusCode      = (int)HttpStatusCode.OK;
                    context.Response.ContentType     = "text/plain";
                    context.Response.ContentLength64 = buffer.Length;

                    using (Stream s = context.Response.OutputStream)
                    {
                        s.Write(buffer, 0, buffer.Length);
                    }
                }
            }
        }