aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/Local/LocalUserServices.cs
blob: 6cf254bd8beb27c35c35db5eb1bedebd0452a01b (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using OpenSim.Framework.Communications;
//using OpenSim.Framework.User;
using OpenSim.Framework.UserManagement;
using OpenSim.Framework.Data;
using OpenSim.Framework.Types;
using OpenSim.Framework.Utilities;

using libsecondlife;

namespace OpenSim.Region.Communications.Local
{
    public class LocalUserServices : UserManagerBase, IUserServices
    {
        private CommunicationsLocal m_Parent;

        private uint defaultHomeX ;
        private uint defaultHomeY;
        public LocalUserServices(CommunicationsLocal parent, uint defHomeX, uint defHomeY)
        {
            m_Parent = parent;
            defaultHomeX = defHomeX;
            defaultHomeY = defHomeY;
        }

        public UserProfileData GetUserProfile(string firstName, string lastName)
        {
            return GetUserProfile(firstName + " " + lastName);
        }

        public UserProfileData GetUserProfile(string name)
        {
            return this.getUserProfile(name);
        }

        public UserProfileData GetUserProfile(LLUUID avatarID)
        {
            return this.getUserProfile(avatarID);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string GetMessage()
        {
            return "Welcome to OpenSim";
        }

        public override UserProfileData GetTheUser(string firstname, string lastname)
        {
            UserProfileData profile = getUserProfile(firstname, lastname);
            if (profile != null)
            {
               
                return profile;
            }

            //no current user account so make one
            Console.WriteLine("No User account found so creating a new one ");
            this.AddUserProfile(firstname, lastname, "test", defaultHomeX, defaultHomeY);
            
            profile = getUserProfile(firstname, lastname);

            return profile;
        }

        public override bool AuthenticateUser(ref UserProfileData profile, string password)
        {
            //for now we will accept any password in sandbox mode
            Console.WriteLine("authorising user");
            return true;
        }

        public override void CustomiseResponse(ref LoginResponse response, ref UserProfileData theUser)
        {
            ulong currentRegion = theUser.currentAgent.currentHandle;
            RegionInfo reg = m_Parent.GridServer.RequestNeighbourInfo(currentRegion);


            if (reg != null)
            {
                response.Home = "{'region_handle':[r" + (reg.RegionLocX * 256).ToString() + ",r" + (reg.RegionLocY * 256).ToString() + "], " +
                 "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
                 "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
                string capsPath = Util.GetRandomCapsPath();
                response.SimAddress = reg.CommsExternalAddress;
                response.SimPort = (Int32)reg.CommsIPListenPort;
                response.RegionX = reg.RegionLocX ;
                response.RegionY = reg.RegionLocY ;
                response.SeedCapability = "http://" + reg.CommsIPListenAddr + ":" + "9000" + "/CAPS/" + capsPath + "0000/";
                theUser.currentAgent.currentRegion = reg.SimUUID;
                theUser.currentAgent.currentHandle = reg.RegionHandle;

                Login _login = new Login();
                //copy data to login object
                _login.First = response.Firstname;
                _login.Last = response.Lastname;
                _login.Agent = response.AgentID;
                _login.Session = response.SessionID;
                _login.SecureSession = response.SecureSessionID;
                _login.CircuitCode = (uint)response.CircuitCode;
                _login.CapsPath = capsPath;

                m_Parent.InformRegionOfLogin(currentRegion, _login);
            }
            else
            {
                Console.WriteLine("not found region " + currentRegion);
            }

        }

        public UserProfileData SetupMasterUser(string firstName, string lastName)
        {
            return SetupMasterUser(firstName, lastName, "");
        }

        public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
        {
            UserProfileData profile = getUserProfile(firstName, lastName);
            if (profile != null)
            {

                return profile;
            }

            Console.WriteLine("Unknown Master User. Sandbox Mode: Creating Account");
            this.AddUserProfile(firstName, lastName, password, defaultHomeX, defaultHomeY);

            profile = getUserProfile(firstName, lastName);

            if (profile == null)
            {
                Console.WriteLine("Unknown Master User after creation attempt. No clue what to do here.");
            }

            return profile;
        }
    }
}