- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
private void _Login()
        {
            if (Get_IPAdress_Server() != 0)
            {
                if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                return;
            }
            try
            {
                TcpClient MClient = new TcpClient(Server_IPAdress, Server_Port);
                Sock = MClient.Client;
                if (Sock == null)
                {
                    if (Error_Connect_Method != null) Error_Connect_Method(this ,"Серевер недоступен!");
                    return;
                }
                mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_HELLO, 0, 0, 0, 0, 0, 0, 0);
                byte[] Hello = Pack.Generat_Packet();
                Sock.Send(Hello);
                byte[] Buf = new byte[48];
                Sock.Receive(Buf);
                if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_HELLO_ACK)
                {
                    Sock.Close();
                    if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                }
                Ping_Timer = new System.Timers.Timer();
                long j = 0;
                Ping_Timer.Interval = mrim_packet_header.Get_UL(Buf.Skip(44).ToArray(), ref j) * 1000;
                Ping_Timer.Elapsed += new System.Timers.ElapsedEventHandler(Send_Ping);
                Ping_Timer.Start();
                Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_LOGIN2, 0, 0, 0, 0, 0, 0, 0);
                Pack.Add_Date_LPS(new string[] {Login, Password });
                Pack.Add_Date_UL(new long[] { Status });
                Pack.Add_Date_LPS(new string[] { User_Agent });
                byte[] Auth = Pack.Generat_Packet();
                Sock.Send(Auth);
                Buf = new byte[48];
                Sock.Receive(Buf);
                byte[] Date_Len;
                byte[] Date;
                if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_LOGIN_ACK)
                {
                    Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                    Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                    int N = Sock.Receive(Date);
                    mrim.mrim_packet_header.Loger(Date, N);
                    if (Error_Connect_Method != null) Error_Connect_Method(this, Encoding.GetEncoding("windows-1251").GetString(Date));
                    return;
                }
                if (Complite_Connect_Method != null) Complite_Connect_Method(this);
                Sock.Receive(Buf = new byte[44]);
                if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) == Msg.MRIM_CS_USER_INFO)
                {
                    Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                    Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                    int N = Sock.Receive(Date);
                    long M = 0;
                    long J = 0;
                    byte[] Buf_Text;
                    while (N > J)