aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/ClientView.Grid.cs
blob: 5229dbd337c58019673e99ae5ee6032fc9c13965 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;
using libsecondlife.Packets;
using Nwc.XmlRpc;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Timers;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Types;
using OpenSim.Framework.Inventory;
using OpenSim.Framework.Utilities;
using OpenSim.world;
using OpenSim.Assets;

namespace OpenSim
{
    public partial class ClientView
    {

        public void EnableNeighbours()
        {
            if ((this.m_gridServer.GetName() == "Remote") && (!this.m_child))
            {
                Hashtable SimParams;
                ArrayList SendParams;
                XmlRpcRequest GridReq;
                XmlRpcResponse GridResp;
                List<Packet> enablePackets = new List<Packet>();

                RemoteGridBase gridServer = (RemoteGridBase)this.m_gridServer;

                foreach (Hashtable neighbour in gridServer.neighbours)
                {
                    try
                    {
                        string neighbourIPStr = (string)neighbour["sim_ip"];
                        System.Net.IPAddress neighbourIP = System.Net.IPAddress.Parse(neighbourIPStr);
                        ushort neighbourPort = (ushort)Convert.ToInt32(neighbour["sim_port"]);
                        string reqUrl = "http://" + neighbourIPStr + ":" + neighbourPort.ToString();

                        Console.WriteLine(reqUrl);

                        SimParams = new Hashtable();
                        SimParams["session_id"] = this.SessionID.ToString();
                        SimParams["secure_session_id"] = this.SecureSessionID.ToString();
                        SimParams["firstname"] = this.ClientAvatar.firstname;
                        SimParams["lastname"] = this.ClientAvatar.lastname;
                        SimParams["agent_id"] = this.AgentID.ToString();
                        SimParams["circuit_code"] = (Int32)this.CircuitCode;
                        SimParams["child_agent"] = "1";
                        SendParams = new ArrayList();
                        SendParams.Add(SimParams);

                        GridReq = new XmlRpcRequest("expect_user", SendParams);
                        GridResp = GridReq.Send(reqUrl, 3000);
                        EnableSimulatorPacket enablesimpacket = new EnableSimulatorPacket();
                        enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
                        enablesimpacket.SimulatorInfo.Handle = Helpers.UIntsToLong((uint)(Convert.ToInt32(neighbour["region_locx"]) * 256), (uint)(Convert.ToInt32(neighbour["region_locy"]) * 256));


                        byte[] byteIP = neighbourIP.GetAddressBytes();
                        enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
                        enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
                        enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
                        enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
                        enablesimpacket.SimulatorInfo.Port = neighbourPort;
                        enablePackets.Add(enablesimpacket);
                    }
                    catch (Exception e)
                    {
                        OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Could not connect to neighbour " + neighbour["sim_ip"] + ":" + neighbour["sim_port"] + ", continuing.");
                    }
                }
                Thread.Sleep(3000);
                foreach (Packet enable in enablePackets)
                {
                    this.OutPacket(enable);
                }
                enablePackets.Clear();

            }
        }

        public void CrossSimBorder(LLVector3 avatarpos)
        {		// VERY VERY BASIC

            LLVector3 newpos = avatarpos;
            uint neighbourx = this.m_regionData.RegionLocX;
            uint neighboury = this.m_regionData.RegionLocY;

            if (avatarpos.X < 0)
            {
                neighbourx -= 1;
                newpos.X = 254;
            }
            if (avatarpos.X > 255)
            {
                neighbourx += 1;
                newpos.X = 1;
            }
            if (avatarpos.Y < 0)
            {
                neighboury -= 1;
                newpos.Y = 254;
            }
            if (avatarpos.Y > 255)
            {
                neighboury += 1;
                newpos.Y = 1;
            }
            OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "SimClient.cs:CrossSimBorder() - Crossing border to neighbouring sim at [" + neighbourx.ToString() + "," + neighboury.ToString() + "]");

            Hashtable SimParams;
            ArrayList SendParams;
            XmlRpcRequest GridReq;
            XmlRpcResponse GridResp;
            foreach (Hashtable borderingSim in ((RemoteGridBase)m_gridServer).neighbours)
            {
                if (((string)borderingSim["region_locx"]).Equals(neighbourx.ToString()) && ((string)borderingSim["region_locy"]).Equals(neighboury.ToString()))
                {
                    SimParams = new Hashtable();
                    SimParams["firstname"] = this.ClientAvatar.firstname;
                    SimParams["lastname"] = this.ClientAvatar.lastname;
                    SimParams["circuit_code"] = this.CircuitCode.ToString();
                    SimParams["pos_x"] = newpos.X.ToString();
                    SimParams["pos_y"] = newpos.Y.ToString();
                    SimParams["pos_z"] = newpos.Z.ToString();
                    SendParams = new ArrayList();
                    SendParams.Add(SimParams);

                    GridReq = new XmlRpcRequest("agent_crossing", SendParams);
                    GridResp = GridReq.Send("http://" + borderingSim["sim_ip"] + ":" + borderingSim["sim_port"], 3000);

                    CrossedRegionPacket NewSimPack = new CrossedRegionPacket();
                    NewSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
                    NewSimPack.AgentData.AgentID = this.AgentID;
                    NewSimPack.AgentData.SessionID = this.SessionID;
                    NewSimPack.Info = new CrossedRegionPacket.InfoBlock();
                    NewSimPack.Info.Position = newpos;
                    NewSimPack.Info.LookAt = new LLVector3(0.99f, 0.042f, 0);	// copied from Avatar.cs - SHOULD BE DYNAMIC!!!!!!!!!!
                    NewSimPack.RegionData = new libsecondlife.Packets.CrossedRegionPacket.RegionDataBlock();
                    NewSimPack.RegionData.RegionHandle = Helpers.UIntsToLong((uint)(Convert.ToInt32(borderingSim["region_locx"]) * 256), (uint)(Convert.ToInt32(borderingSim["region_locy"]) * 256));
                    System.Net.IPAddress neighbourIP = System.Net.IPAddress.Parse((string)borderingSim["sim_ip"]);
                    byte[] byteIP = neighbourIP.GetAddressBytes();
                    NewSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
                    NewSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
                    NewSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
                    NewSimPack.RegionData.SimIP += (uint)byteIP[0];
                    NewSimPack.RegionData.SimPort = (ushort)Convert.ToInt32(borderingSim["sim_port"]);
                    NewSimPack.RegionData.SeedCapability = new byte[0];
                    lock (PacketQueue)
                    {
                        ProcessOutPacket(NewSimPack);
                        DowngradeClient();
                    }
                }
            }
        }
   }
}