1
0

CheckSumServer.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Text;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Timers;
  8. using System.Reflection;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using libsecondlife;
  12. using libsecondlife.Packets;
  13. using OpenSim.Framework.Console;
  14. namespace OpenSim.Servers
  15. {
  16. public class CheckSumServer : UDPServerBase
  17. {
  18. //protected ConsoleBase m_console;
  19. public CheckSumServer(int port)
  20. : base(port)
  21. {
  22. }
  23. protected override void OnReceivedData(IAsyncResult result)
  24. {
  25. ipeSender = new IPEndPoint(IPAddress.Any, 0);
  26. epSender = (EndPoint)ipeSender;
  27. Packet packet = null;
  28. int numBytes = Server.EndReceiveFrom(result, ref epSender);
  29. int packetEnd = numBytes - 1;
  30. packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
  31. if (packet.Type == PacketType.SecuredTemplateChecksumRequest)
  32. {
  33. SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet;
  34. TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket();
  35. checkreply.DataBlock.Checksum = 3220703154;//180572585;
  36. checkreply.DataBlock.Flags = 0;
  37. checkreply.DataBlock.MajorVersion = 1;
  38. checkreply.DataBlock.MinorVersion = 15;
  39. checkreply.DataBlock.PatchVersion = 0;
  40. checkreply.DataBlock.ServerVersion = 0;
  41. checkreply.TokenBlock.Token = checksum.TokenBlock.Token;
  42. this.SendPacket(checkreply, epSender);
  43. /*
  44. //if we wanted to echo the the checksum/ version from the client (so that any client worked)
  45. SecuredTemplateChecksumRequestPacket checkrequest = new SecuredTemplateChecksumRequestPacket();
  46. checkrequest.TokenBlock.Token = checksum.TokenBlock.Token;
  47. this.SendPacket(checkrequest, epSender);
  48. */
  49. }
  50. else if (packet.Type == PacketType.TemplateChecksumReply)
  51. {
  52. //echo back the client checksum reply (Hegemon's method)
  53. TemplateChecksumReplyPacket checksum2 = (TemplateChecksumReplyPacket)packet;
  54. TemplateChecksumReplyPacket checkreply2 = new TemplateChecksumReplyPacket();
  55. checkreply2.DataBlock.Checksum = checksum2.DataBlock.Checksum;
  56. checkreply2.DataBlock.Flags = checksum2.DataBlock.Flags;
  57. checkreply2.DataBlock.MajorVersion = checksum2.DataBlock.MajorVersion;
  58. checkreply2.DataBlock.MinorVersion = checksum2.DataBlock.MinorVersion;
  59. checkreply2.DataBlock.PatchVersion = checksum2.DataBlock.PatchVersion;
  60. checkreply2.DataBlock.ServerVersion = checksum2.DataBlock.ServerVersion;
  61. checkreply2.TokenBlock.Token = checksum2.TokenBlock.Token;
  62. this.SendPacket(checkreply2, epSender);
  63. }
  64. else
  65. {
  66. }
  67. Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
  68. }
  69. private void SendPacket(Packet Pack, EndPoint endp)
  70. {
  71. if (!Pack.Header.Resent)
  72. {
  73. Pack.Header.Sequence = 1;
  74. }
  75. byte[] ZeroOutBuffer = new byte[4096];
  76. byte[] sendbuffer;
  77. sendbuffer = Pack.ToBytes();
  78. try
  79. {
  80. if (Pack.Header.Zerocoded)
  81. {
  82. int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
  83. this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp);
  84. }
  85. else
  86. {
  87. this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp);
  88. }
  89. }
  90. catch (Exception)
  91. {
  92. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection ");
  93. }
  94. }
  95. private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp)
  96. {
  97. this.Server.SendTo(buffer, size, flags, endp);
  98. }
  99. }
  100. }