From 8a931a4e914a00cbf0e853b83e74e56ace08419e Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 27 Dec 2009 16:07:05 +1100 Subject: * Implements some basic Sirikata protocol work (initial handshakes). --- .../Sirikata/ClientStack/SirikataClientView.cs | 21 ++++++++++++ OpenSim/Client/Sirikata/SirikataModule.cs | 37 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs b/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs index 78f231a..e8d1889 100644 --- a/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs +++ b/OpenSim/Client/Sirikata/ClientStack/SirikataClientView.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Net.Sockets; using System.Text; using OpenMetaverse; using OpenMetaverse.Packets; @@ -11,6 +12,26 @@ namespace OpenSim.Client.Sirikata.ClientStack { class SirikataClientView : IClientAPI, IClientCore { + private readonly NetworkStream stream; + + public SirikataClientView(TcpClient client) + { + stream = client.GetStream(); + + sessionId = UUID.Random(); + + + // Handshake with client + string con = "SSTTCP01" + sessionId; + byte[] handshake = Util.UTF8.GetBytes(con); + + byte[] clientHandshake = new byte[2+6+36]; + + stream.Read(clientHandshake, 0, handshake.Length); + stream.Write(handshake, 0, handshake.Length - 1); // Remove null terminator (hence the -1) + } + + #region Implementation of IClientAPI private Vector3 startPos; diff --git a/OpenSim/Client/Sirikata/SirikataModule.cs b/OpenSim/Client/Sirikata/SirikataModule.cs index d2d7ff8..cbb6c23 100644 --- a/OpenSim/Client/Sirikata/SirikataModule.cs +++ b/OpenSim/Client/Sirikata/SirikataModule.cs @@ -60,8 +60,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; using Nini.Config; using OpenMetaverse; +using OpenSim.Client.Sirikata.ClientStack; using OpenSim.Framework; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; @@ -72,18 +75,50 @@ namespace OpenSim.Client.Sirikata { class SirikataModule : IRegionModule { + private bool m_enabled = false; + + private TcpListener m_listener; + private bool m_running = true; + + private List m_scenes = new List(); + private Dictionary m_clients = new Dictionary(); + #region Implementation of IRegionModule public void Initialise(Scene scene, IConfigSource source) { - + lock (m_scenes) + m_scenes.Add(scene); } public void PostInitialise() { + if(!m_enabled) + return; + + m_listener = new TcpListener(IPAddress.Any, 5943); } + private void ListenLoop() + { + while(m_running) + { + m_listener.BeginAcceptTcpClient(AcceptSocket, m_listener); + } + } + + private void AcceptSocket(IAsyncResult ar) + { + TcpListener listener = (TcpListener) ar.AsyncState; + TcpClient client = listener.EndAcceptTcpClient(ar); + + SirikataClientView clientView = new SirikataClientView(client); + + lock (m_clients) + m_clients.Add(clientView.SessionId, clientView); + } + public void Close() { -- cgit v1.1