Си диез / Говнокод #3687 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;


namespace GisClient
{
    class EntryPoint
    {
        static void Main()
        {
            TcpClient TcpCli = new TcpClient("127.0.0.1", 15800);
            NetworkStream ns = TcpCli.GetStream();
            
            PacketStructure obj = new PacketStructure();
            obj.CommandOptions = 0x80; //What's this shit??? 0x80 , what's Encoding??? What 0x80 equals to?

            obj.Write2Net(ns);
            obj.ReadFromNet(ns);
        }
    }

    class PacketStructure
    {
        UInt32 PacketId = 0x35534947;
        Guid UserId = new Guid();
        
        public byte CommandOptions = 0;
        UInt32 CommandSize = 0;

        byte[] Reserved = new byte[3];


        public void Write2BufferStream(MemoryStream ms)
        {
            //PacketId || Length - 4 || Type - UInt32
            ms.Write(BitConverter.GetBytes(PacketId), 0, 4);
            //UserId || Length - 16 || Type - byte[16]
            ms.Write(UserId.ToByteArray(), 0, 16);
            //Command Options || Length - 1 || byte
            ms.Write(BitConverter.GetBytes(CommandOptions), 0, 1);
            //Command Size || Length - 4 || Int32
            ms.Write(BitConverter.GetBytes(CommandSize), 0, 4);
            //Reserved space || Length - 3 || byte[3]
            ms.Write(Reserved, 0, 3);
            //CRC32 - control summary
            ms.Write(BitConverter.GetBytes(CRC32.BytesCrc(ms.ToArray())), 0, 4);
        }

        public void Write2Net(NetworkStream ns)
        {
            MemoryStream ms = new MemoryStream();

            Write2BufferStream(ms);

            byte[] A = ms.ToArray();
            ns.Write(A, 0, (int)ns.Length);
        }

        public void ReadFromNet(NetworkStream ns)
        {
            byte[] B = new byte[32];

            ns.Read(B, 0, (int)ns.Length);

            PacketId = BitConverter.ToUInt32(B, 0); //??????? lolwhat?????!!!!!111

            byte[] C = new byte[16];

            for (int i = 0; i < 16; i++)
            {
                C[i] = C[i + 4];
            }

            foreach (int i in C)
            {
                Console.WriteLine(i);
                Console.ReadLine();
            }

            UserId = new Guid(C);

            CommandOptions = B[20]; // Why no BitConverter?????!!!!!

            CommandSize = BitConverter.ToUInt32(B, 21); // The end of CommandSize IS NOT SET!!!!1111

            for (int i = 0; i < 3; i++) Reserved[i] = B[i + 25]; // A[0] = Packet[0 + 25] IF i = 0 THEN i++

            Console.ReadLine();
        }

    }
}

Код с работы, вот так вот мы отслыаем и принимаем пакеты по TCP.
Комменатрии особенно доставляют удовольствие :)

Запостил: sergylens sergylens, (Updated )

Комментарии (1) RSS

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8