aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Examples/SimpleApp/MyWorld.cs
blob: 27775f12a5733b59b8275f3191e8ae49407e7e67 (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
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Types;
using OpenSim.Framework.Console;
using libsecondlife;

namespace SimpleApp
{
    public class MyWorld : IWorld
    {
        private RegionInfo m_regionInfo;

        public MyWorld(RegionInfo regionInfo)
        {
            m_regionInfo = regionInfo;
        }

        private void SendLayerData(IClientAPI remoteClient)
        {
            float[] map = new float[65536];

            for (int i = 0; i < 65536; i++)
            {
                int x = i % 256;
                int y = i / 256;

                map[i] = (float)(x + y / 2);
            }

            remoteClient.SendLayerData(map);
        }

        #region IWorld Members

        void IWorld.AddNewAvatar(IClientAPI client, LLUUID agentID, bool child)
        {
            LLVector3 pos = new LLVector3(128, 128, 128);
            
            client.OnRegionHandShakeReply += SendLayerData;
            client.OnChatFromViewer +=
                delegate(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
                    {
                        // Echo it (so you know what you typed)
                        client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
                        client.SendChatMessage("Ready.", 1, pos, "System", LLUUID.Zero );
                    };
            
            client.OnRequestWearables += SendWearables;

            client.OnCompleteMovementToRegion += delegate()
                {
                    client.MoveAgentIntoRegion(m_regionInfo);
                };

            client.OnCompleteMovementToRegion += delegate()
                 {
                     client.SendAvatarData(m_regionInfo, client.FirstName,
                                           client.LastName, client.AgentId, 0,
                                           pos);
                                                         
                     client.SendChatMessage("Welcome to My World.", 1, pos, "System", LLUUID.Zero );
                 };

            client.SendRegionHandshake(m_regionInfo);

        }

        private void SendWearables( IClientAPI client )
        {
            client.SendWearables( AvatarWearable.DefaultWearables );
        }

        void IWorld.RemoveAvatar(LLUUID agentID)
        {

        }

        RegionInfo IWorld.RegionInfo
        {
            get { return m_regionInfo; }
        }

        object IWorld.SyncRoot
        {
            get { return this; }
        }

        private uint m_nextLocalId = 1;

        uint IWorld.NextLocalId
        {
            get { return m_nextLocalId++; }
        }

        #endregion


    }
}