CheckSumServer.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. namespace OpenSim.Framework.Servers
  29. {/*
  30. public class CheckSumServer : UDPServerBase
  31. {
  32. //protected ConsoleBase m_log;
  33. public CheckSumServer(int port)
  34. : base(port)
  35. {
  36. }
  37. protected override void OnReceivedData(IAsyncResult result)
  38. {
  39. ipeSender = new IPEndPoint(IPAddress.Any, 0);
  40. epSender = (EndPoint)ipeSender;
  41. Packet packet = null;
  42. int numBytes = Server.EndReceiveFrom(result, ref epSender);
  43. int packetEnd = numBytes - 1;
  44. packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
  45. if (packet.Type == PacketType.SecuredTemplateChecksumRequest)
  46. {
  47. SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet;
  48. TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket();
  49. checkreply.DataBlock.Checksum = 3220703154;//180572585;
  50. checkreply.DataBlock.Flags = 0;
  51. checkreply.DataBlock.MajorVersion = 1;
  52. checkreply.DataBlock.MinorVersion = 15;
  53. checkreply.DataBlock.PatchVersion = 0;
  54. checkreply.DataBlock.ServerVersion = 0;
  55. checkreply.TokenBlock.Token = checksum.TokenBlock.Token;
  56. this.SendPacket(checkreply, epSender);
  57. /*
  58. //if we wanted to echo the the checksum/ version from the client (so that any client worked)
  59. SecuredTemplateChecksumRequestPacket checkrequest = new SecuredTemplateChecksumRequestPacket();
  60. checkrequest.TokenBlock.Token = checksum.TokenBlock.Token;
  61. this.SendPacket(checkrequest, epSender);
  62. }
  63. else if (packet.Type == PacketType.TemplateChecksumReply)
  64. {
  65. //echo back the client checksum reply (Hegemon's method)
  66. TemplateChecksumReplyPacket checksum2 = (TemplateChecksumReplyPacket)packet;
  67. TemplateChecksumReplyPacket checkreply2 = new TemplateChecksumReplyPacket();
  68. checkreply2.DataBlock.Checksum = checksum2.DataBlock.Checksum;
  69. checkreply2.DataBlock.Flags = checksum2.DataBlock.Flags;
  70. checkreply2.DataBlock.MajorVersion = checksum2.DataBlock.MajorVersion;
  71. checkreply2.DataBlock.MinorVersion = checksum2.DataBlock.MinorVersion;
  72. checkreply2.DataBlock.PatchVersion = checksum2.DataBlock.PatchVersion;
  73. checkreply2.DataBlock.ServerVersion = checksum2.DataBlock.ServerVersion;
  74. checkreply2.TokenBlock.Token = checksum2.TokenBlock.Token;
  75. this.SendPacket(checkreply2, epSender);
  76. }
  77. else
  78. {
  79. }
  80. Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
  81. }
  82. private void SendPacket(Packet Pack, EndPoint endp)
  83. {
  84. if (!Pack.Header.Resent)
  85. {
  86. Pack.Header.Sequence = 1;
  87. }
  88. byte[] ZeroOutBuffer = new byte[4096];
  89. byte[] sendbuffer;
  90. sendbuffer = Pack.ToBytes();
  91. try
  92. {
  93. if (Pack.Header.Zerocoded)
  94. {
  95. int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
  96. this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp);
  97. }
  98. else
  99. {
  100. this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp);
  101. }
  102. }
  103. catch (Exception)
  104. {
  105. OpenSim.Framework.Console.MainLog.Instance.Warn("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection ");
  106. }
  107. }
  108. private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp)
  109. {
  110. this.Server.SendTo(buffer, size, flags, endp);
  111. }
  112. * }
  113. */
  114. }