Ejemplo n.º 1
0
    /// <summary>
    /// Отправка СМС
    /// </summary>
    public void Send_Sms(string _Phone, string _Text)
    {
        //my_header_sms = pack(formt, CS_MAGIC, PROTO_VERSION, 3, MRIM_CS_SMS, dlen) + pack('<L', 0)*6 + mydata
        mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_SMS, 0, 0, 0, 0, 0, 0, 0);

        Pack.Add_Date_UL(new long[] { 0 });
        Pack.Add_Date_LPS(new string[] { _Phone, _Text });
        byte[] SMS_Send = Pack.Generat_Packet();
        Console.WriteLine(BitConverter.ToString(SMS_Send));
        Sock.Send(SMS_Send);
    }
Ejemplo n.º 2
0
    private void Send_Ping(object Sender, EventArgs args)
    {
        Console.WriteLine("Send ping");
        mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_PING, 0, 0, 0, 0, 0, 0, 0);

        byte[] Ping = Pack.Generat_Packet();
        lock (Sock)
        {
            Sock.Send(Ping);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Авторизация на сервере Mrim
    /// </summary>
    public int Login(string _Login, string _Password, long _Status)
    {
        if (Get_IPAdress_Server() != 0)
        {
            return(-2);
        }
        try
        {
            TcpClient MClient = new TcpClient(User_Struct.Server_IPAdress, User_Struct.Server_Port);
            Sock = MClient.Client;
            if (Sock == null)
            {
                Console.WriteLine("Серевер недоступен!");
                return(-1);
            }
            mrim_packet_header Pack  = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.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();
                Console.WriteLine("Серевер недоступен!");
                return(-3);
            }
            System.Timers.Timer Ping_Timer = new System.Timers.Timer();
            long j = 0;
            Ping_Timer.Interval = mrim_packet_header.Get_UL(Buf.Skip(44).ToArray(), ref j) * 100;
            Ping_Timer.Elapsed += new System.Timers.ElapsedEventHandler(Send_Ping);
            Ping_Timer.Start();
            Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_LOGIN2, 1, 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_Struct.User_Agent });
            byte[] Auth = Pack.Generat_Packet();
            Console.WriteLine(BitConverter.ToString(Auth));
            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_REJ)
            {
                Date_Len = new byte[4] {
                    Buf[16], Buf[17], Buf[18], Buf[19]
                };
                Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                Sock.Receive(Date);
                return(-4);
            }

            return(0);
        }
        catch (SocketException e)
        {
            Sock.Close();
            Console.WriteLine(e.Message);
            return(-100);
        }
    }