aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Client/VWoHTTP/VWoHTTPModule.cs
blob: c5b5c091132308643e2ba255778edc54e61d2cd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Text;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Client.VWoHTTP.ClientStack;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;

namespace OpenSim.Client.VWoHTTP
{
    class VWoHTTPModule : IRegionModule, IHttpAgentHandler
    {
        private bool m_disabled = true;

        private IHttpServer m_httpd;

        private readonly List<Scene> m_scenes = new List<Scene>();

        private Dictionary<UUID, VWHClientView> m_clients = new Dictionary<UUID, VWHClientView>();

        #region Implementation of IRegionModule

        public void Initialise(Scene scene, IConfigSource source)
        {
            if(m_disabled)
                return;

            m_scenes.Add(scene);

            m_httpd = scene.CommsManager.HttpServer;
        }

        public void PostInitialise()
        {
            if (m_disabled)
                return;

            m_httpd.AddAgentHandler("vwohttp", this);
        }

        public void Close()
        {
            if (m_disabled)
                return;

            m_httpd.RemoveAgentHandler("vwohttp", this);
        }

        public string Name
        {
            get { return "VWoHTTP ClientStack"; }
        }

        public bool IsSharedModule
        {
            get { return true; }
        }

        #endregion

        #region Implementation of IHttpAgentHandler

        public bool Handle(OSHttpRequest req, OSHttpResponse resp)
        {
            string[] urlparts = req.Url.AbsolutePath.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);

            if (urlparts.Length < 2)
                return false;

            if (urlparts[1] == "connect")
            {
                UUID sessID = UUID.Random();

                VWHClientView client = new VWHClientView(sessID, UUID.Random(), "VWoHTTPClient", m_scenes[0]);

                m_clients.Add(sessID, client);

                return true;
            }
            else
            {
                if (urlparts.Length < 3)
                    return false;

                UUID sessionID;
                if (!UUID.TryParse(urlparts[1], out sessionID))
                    return false;

                if (!m_clients.ContainsKey(sessionID))
                    return false;

                return m_clients[sessionID].ProcessInMsg(req, resp);
            }
        }

        public bool Match(OSHttpRequest req, OSHttpResponse resp)
        {
            return req.Url.ToString().Contains("vwohttp");
        }

        #endregion
    }
}