Роботы, плагины и скрипты к чату MyChat. Разработка альтернативных клиентов и различных утилит. Технические вопросы по программированию, замечания и предложения по развитию API
Аватара пользователя
Георгий Лысенко
Код: Выделить всё
using System;
using System.Net.Sockets;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using System.Text;


namespace Client
{
    class PrivateMessage
    {
        public string UserTo { get; set; }
        public string UserFrom { get; set; }
        public string Msg { get; set; }
        public string hash { get; set; }
        public string APIStype { get; set; }
        public string ServerKey { get; set; }
    }
    class AddBBSMessage
    {
        public string ServerKey { get; set; }
        public string APIStyle { get; set; }
        public string UserFrom { get; set; }
        public string Expired { get; set; }
        public string Sticky { get; set; }
        public string Msg { get; set; }

    }
    class Program
    {
        static void Main(string[] args)
        {
            PrivateMessage PM = new PrivateMessage();
            PM.UserTo = "1";
            PM.UserFrom = "0";
            PM.Msg = "Message";
            PM.hash = "";
            PM.APIStype = "c#";
            PM.ServerKey = "iddqd";
            string json_send_message = JsonConvert.SerializeObject(PM);

            AddBBSMessage add_bbs = new AddBBSMessage();
            add_bbs.ServerKey = "iddqd";
            add_bbs.APIStyle = "c#";
            add_bbs.UserFrom = "1";
            add_bbs.Expired = "15.06.2016.12.00.00";
            add_bbs.Sticky = "true";
            add_bbs.Msg = @"text ";
            string json_add_bbs = JsonConvert.SerializeObject(add_bbs);



            string CRLF = "\u000D\u000A";
            string MagicPacket = "\u0017\u0006";
            string cs_integration_api = "0077";
            string iFlag = "30";
            string MCIAPI_CS_SendPrivateMessage = "0002";
            string MCIAPI_CS_AddBBSMessage = "0008";


            TcpClient client = new TcpClient();
            client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2004));

            StreamWriter sw = new StreamWriter(client.GetStream(), Encoding.GetEncoding(1251));
            sw.AutoFlush = true;
            string message = "mc5.20" + CRLF;
            Console.WriteLine("Client : " + message);
            sw.WriteLine(message);

            StreamReader sr = new StreamReader(client.GetStream(), Encoding.GetEncoding(1251));
            Console.WriteLine("Server : " + sr.ReadLine());

            //Send BBS message
            /*Console.WriteLine("Client : " + MagicPacket + cs_integration_api + iFlag + MCIAPI_CS_AddBBSMessage + json_add_bbs + CRLF);
            sw.WriteLine(MagicPacket + cs_integration_api + iFlag + MCIAPI_CS_AddBBSMessage + json_add_bbs + CRLF);
            Console.WriteLine("Server : " + sr.ReadLine());*/

            //Send private message
            Console.WriteLine("Client : " + MagicPacket + cs_integration_api + iFlag + MCIAPI_CS_SendPrivateMessage + json_send_message + CRLF);
            sw.WriteLine(MagicPacket + cs_integration_api + iFlag + MCIAPI_CS_SendPrivateMessage + json_send_message + CRLF);
            Console.WriteLine("Server : " + sr.ReadLine());

            client.Close();

            Console.ReadKey();
        }
    }
}