Пример отправки приватного сообщения в чат на языке C#
Отправляется приватное сообщение от имени встроенного бота (UIN 0) для пользователя с UIN = 1.
// MyChat IntegrationAPI C# example
// Created by Georgiy Lysenko / Network Software Solutions
// Jun 15, 2016
// support@nsoft-s.com
// https://nsoft-s.com/forum/viewtopic.php?f=35&t=4352 (russian support)
// --------------------------------------------------------------------------
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();
}
}
}