CheckSumServer.cs 5.7 KB

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