SirikataModule.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. // THIS MODULE USES CODE FROM SIRIKATA, THE SIRIKATA LICENSE IS BELOW
  27. /*
  28. Sirikata is Licensed using the revised BSD license.
  29. If you have any questions, contact Patrick Horn at <[email protected]>
  30. Copyright (c) 2008, the Sirikata developers (see AUTHORS file for credit).
  31. All rights reserved.
  32. Redistribution and use in source and binary forms, with or without
  33. modification, are permitted provided that the following conditions are
  34. met:
  35. * Redistributions of source code must retain the above copyright
  36. notice, this list of conditions and the following disclaimer.
  37. * Redistributions in binary form must reproduce the above copyright
  38. notice, this list of conditions and the following disclaimer in
  39. the documentation and/or other materials provided with the
  40. distribution.
  41. * Neither the name of Sirikata nor the names of its contributors may
  42. be used to endorse or promote products derived from this software
  43. without specific prior written permission.
  44. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  45. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  47. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  48. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  51. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  52. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  53. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  54. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55. */
  56. using System;
  57. using System.Collections.Generic;
  58. using System.Net;
  59. using System.Net.Sockets;
  60. using Nini.Config;
  61. using OpenMetaverse;
  62. using OpenSim.Client.Sirikata.ClientStack;
  63. using OpenSim.Framework;
  64. using OpenSim.Framework.Servers;
  65. using OpenSim.Framework.Servers.HttpServer;
  66. using OpenSim.Region.Framework.Interfaces;
  67. using OpenSim.Region.Framework.Scenes;
  68. namespace OpenSim.Client.Sirikata
  69. {
  70. class SirikataModule : IRegionModule
  71. {
  72. private bool m_enabled = false;
  73. private TcpListener m_listener;
  74. private bool m_running = true;
  75. private List<Scene> m_scenes = new List<Scene>();
  76. private Dictionary<UUID,SirikataClientView> m_clients = new Dictionary<UUID, SirikataClientView>();
  77. #region Implementation of IRegionModule
  78. public void Initialise(Scene scene, IConfigSource source)
  79. {
  80. lock (m_scenes)
  81. m_scenes.Add(scene);
  82. }
  83. public void PostInitialise()
  84. {
  85. if (!m_enabled)
  86. return;
  87. m_listener = new TcpListener(IPAddress.Any, 5943);
  88. }
  89. private void ListenLoop()
  90. {
  91. while (m_running)
  92. {
  93. m_listener.BeginAcceptTcpClient(AcceptSocket, m_listener);
  94. }
  95. }
  96. private void AcceptSocket(IAsyncResult ar)
  97. {
  98. TcpListener listener = (TcpListener) ar.AsyncState;
  99. TcpClient client = listener.EndAcceptTcpClient(ar);
  100. SirikataClientView clientView = new SirikataClientView(client);
  101. lock (m_clients)
  102. m_clients.Add(clientView.SessionId, clientView);
  103. }
  104. public void Close()
  105. {
  106. }
  107. public string Name
  108. {
  109. get { return "Sirikata ClientStack Module"; }
  110. }
  111. public bool IsSharedModule
  112. {
  113. get { return true; }
  114. }
  115. #endregion
  116. }
  117. }