예제 #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="handler"></param>
 /// <param name="compiler"></param>
 public PageHandler(string pageId, OnPageRequestedHandler handler, PageCompiler compiler)
     : this(pageId, handler, false, compiler)
 {
     _pageId = pageId;
     _onRequest = handler;
     _compiler = compiler;
 }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="handler"></param>
 /// <param name="requireValidation"></param>
 /// <param name="compiler"></param>
 public PageHandler(string pageId, OnPageRequestedHandler handler, bool requireValidation, PageCompiler compiler)
 {
     _pageId = pageId;
     _onRequest = handler;
     _requireValidation = requireValidation;
     _compiler = compiler;
 }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="handler"></param>
 /// <param name="requireValidation"></param>
 /// <param name="compiler"></param>
 public PageHandler(string pageId, OnPageRequestedHandler handler, bool requireValidation, PageCompiler compiler)
 {
     _pageId            = pageId;
     _onRequest         = handler;
     _requireValidation = requireValidation;
     _compiler          = compiler;
 }
예제 #4
0
        private static void OnResetPatchesRequested(string request, PageCompiler compiler, ref Socket socket)
        {
            string id    = Utility.ParseUrl(request, "id");
            IEntry entry = ServerList.GetServerById(id);

            if (entry != null && MessageBox.Show("Are you sure you want to reset patches for " + entry.Name + "?", "ConnectUO Desktop", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                string name = Uri.EscapeDataString(entry.Name);
                string path = Path.Combine(AppSettings.Current.Get <string>("PatchingPath"), Path.Combine("Servers", name));

                if (Directory.Exists(path))
                {
                    bool success = true;
                    try
                    {
                        Directory.Delete(path, true);
                    }
                    catch
                    {
                        success = false;
                    }

                    if (success)
                    {
                        MessageBox.Show("Patches for " + entry.Name + " were reset successfully.", "ConnectUO Desktop");
                    }
                    else
                    {
                        MessageBox.Show("An error occurred while trying to reset the patches for " + entry.Name + ".\n This can be caused by the client still running or some other application that is currently using\n the files in the patch directory for this server.\n Please be sure that nothing is accessing these files and try again.", "ConnectUO Desktop");
                    }
                }
            }

            Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
        }
예제 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="handler"></param>
 /// <param name="compiler"></param>
 public PageHandler(string pageId, OnPageRequestedHandler handler, PageCompiler compiler)
     : this(pageId, handler, false, compiler)
 {
     _pageId    = pageId;
     _onRequest = handler;
     _compiler  = compiler;
 }
예제 #6
0
        private static void OnResetPatchesRequested(string request, PageCompiler compiler, ref Socket socket)
        {
            string id = Utility.ParseUrl(request, "id");
            IEntry entry = ServerList.GetServerById(id);

            if ( entry != null && MessageBox.Show("Are you sure you want to reset patches for " + entry.Name + "?", "ConnectUO Desktop", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                string name = Uri.EscapeDataString(entry.Name);
                string path = Path.Combine(AppSettings.Current.Get<string>("PatchingPath"), Path.Combine("Servers", name));

                if (Directory.Exists(path))
                {
                    bool success = true;
                    try
                    {
                        Directory.Delete(path, true);
                    }
                    catch
                    {
                        success = false;
                    }

                    if (success)
                        MessageBox.Show("Patches for " + entry.Name + " were reset successfully.", "ConnectUO Desktop");
                    else
                        MessageBox.Show("An error occurred while trying to reset the patches for " + entry.Name + ".\n This can be caused by the client still running or some other application that is currently using\n the files in the patch directory for this server.\n Please be sure that nothing is accessing these files and try again.", "ConnectUO Desktop");
                }
            }

            Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
        }
예제 #7
0
 private static void OnEditLocalRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     if (Utility.ParseUrl(request, "mode") != string.Empty)
     {
         MainForm.Instance.addLocalServerToolStripMenuItem_Click(new object[] { request, socket }, null);
     }
     else
         Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
 }
예제 #8
0
 private static void OnEditLocalRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     if (Utility.ParseUrl(request, "mode") != string.Empty)
     {
         MainForm.Instance.addLocalServerToolStripMenuItem_Click(new object[] { request, socket }, null);
     }
     else
     {
         Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
     }
 }
예제 #9
0
 private static void OnPlayRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     Utility.Play(Utility.ParseUrl(request, "id"), Utility.ParseUrl(request, "type"), socket);
 }
예제 #10
0
 private static void Register(string pageId, OnPageRequestedHandler handler, PageCompiler compiler, bool requireValidation)
 {
     _pageHandlers[pageId] = new PageHandler(pageId, handler, requireValidation, compiler);
 }
예제 #11
0
 private static void Register(string pageId, OnPageRequestedHandler handler, PageCompiler compiler)
 {
     _pageHandlers[pageId] = new PageHandler(pageId, handler, compiler);
 }
예제 #12
0
 private static void Register(string pageId, OnPageRequestedHandler handler, PageCompiler compiler, bool requireValidation)
 {
     _pageHandlers[pageId] = new PageHandler(pageId, handler, requireValidation, compiler);
 }
예제 #13
0
 private static void OnAddFavoriteRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     Favorites.AddFavorite(Utility.ParseUrl(request, "id"));
     Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
 }
예제 #14
0
 private static void OnPlayRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     Utility.Play(Utility.ParseUrl(request, "id"), Utility.ParseUrl(request, "type"), socket);
 }
예제 #15
0
 private static void OnRemoveFavoriteRequested(string request, PageCompiler compiler, ref Socket socket)
 {
     Core.Server.SendToBrowser(String.Format(Utility.META_REDIRECT, "http://localhost.:1980/favorites.html"), ref socket);
     Favorites.RemoveFavorite(Uri.UnescapeDataString(Utility.ParseUrl(request, "id")));
 }
예제 #16
0
        private void StartListen()
        {
            int    startPos = 0;
            string request;

            while (true)
            {
                Socket socket = null;

                try
                {
                    socket = _listener.AcceptSocket();

                    if (!socket.RemoteEndPoint.ToString().Contains("127.0.0.1"))
                    {
                        socket.Close();
                    }

                    if (socket.Connected)
                    {
                        if (_buffer == null)
                        {
                            _buffer = new byte[1024];
                        }

                        int i = socket.Receive(_buffer, _buffer.Length, 0);

                        string httpRequest = Encoding.ASCII.GetString(_buffer);
                        startPos = httpRequest.IndexOf("HTTP", 1);
                        string ver = httpRequest.Substring(startPos, 8);
                        request = httpRequest.Substring(5, startPos - 5);
                        request = request.Trim();

                        if (request.Length <= 1)
                        {
                            request = "home.html?page=1";
                        }

                        if (IsTemplateFileRequest(request))
                        {
                            string[] split = request.Split('?');
                            string   ext   = Path.GetExtension(split[0]);

                            string getData = split.Length > 1 ? split[1].Trim() : "";
                            getData = Uri.UnescapeDataString(getData);

                            ext.Trim();

                            if (ext.Contains(".html"))
                            {
                                string output = PageCompiler.CompileCode(Path.Combine(Templates.CurrentTemplate.RootDirectory, split[0]), getData);

                                SendHeader(ver, GetMimeType(split[0]), output.Length, STATUS_CODE_OK, ref socket);
                                SendToBrowser(output, ref socket);
                            }
                            else
                            {
                                FileStream fs   = new FileStream(Path.Combine(Templates.CurrentTemplate.RootDirectory, split[0]), FileMode.Open);
                                byte[]     send = new byte[fs.Length];

                                fs.Read(send, 0, send.Length);
                                fs.Close();

                                SendHeader(ver, GetMimeType(split[0]), send.Length, STATUS_CODE_OK, ref socket);
                                SendToBrowser(send, ref socket);
                            }
                        }
                        else
                        {
                            HandleRequest(request, ref socket);
                        }

                        _lastPageRequest = "http://localhost.:1980/" + request;
                        socket.Close();
                    }
                }
                catch
                {
                    if (socket != null && socket.Connected)
                    {
                        socket.Close();
                    }
                }
            }
        }
예제 #17
0
 private static void Register(string pageId, OnPageRequestedHandler handler, PageCompiler compiler)
 {
     _pageHandlers[pageId] = new PageHandler(pageId, handler, compiler);
 }