Код по отправке смс-сообщений с помощью mrim протокола:
| C# | 1
2
3
4
5
6
7
8
9
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MRIMClient
{
#region ***Идентификаторы сообщений***
struct Msg
{
public const long CS_MAGIC = 0xDEADBEEF; // Клиентский Magic
public const long PROTO_VERSION = 0x10008; // Версия протокола
public const long MRIM_CS_HELLO = 0x1001;
public const long MRIM_CS_HELLO_ACK = 0x1002;
public const long MRIM_CS_LOGIN2 = 0x1038;
public const long MRIM_CS_LOGIN_ACK = 0x1004;
public const long MRIM_CS_LOGIN_REJ = 0x1005;
public const long MRIM_CS_PING = 0x1006;
public const long STATUS_OFFLINE = 0x00000000;
public const long STATUS_ONLINE = 0x00000001;
public const long STATUS_AWAY = 0x00000002;
public const long STATUS_UNDETERMINATED = 0x00000003;
public const long STATUS_FLAG_INVISIBLE = 0x80000000;
public const long MRIM_CS_SMS = 0x1039;
}
#endregion
#region ***User_Struct***
struct User_Struct
{
public static string Server_IPAdress = "";
public static int Server_Port = 0;
public static string Login = "";
public static string Password = "";
public static string Nick_Name = "";
public static string EMail_Total = "0";
public static string EMail_UnRead = "0";
public static int Ping_Time = 0;
public static int Seq = 1;
public static string User_Agent = "pymra 0.1beta"; //Идентификатор клиента
public static string Error_String = "";
}
#endregion
public class mrim_packet_header
{
public long magic; // Magic
public long proto; // Версия протокола
public long seq; // Sequence
public long msg; // Тип пакета
public long dlen; // Длина данных
public long from; // Адрес отправителя
public long fromport; // Порт отправителя
public long reserved_1; //
public long reserved_2; //
public long reserved_3; //
public long reserved_4; //
public byte[] Date;//
public static void Loger(byte[] Buf, int N)
{
string Mass_string = "";
for (int i = 1; i <= N / 4; i++)
{
for (int j = (i * 4) - 1; j > (i * 4) - 5; j--)
{
Mass_string += BitConverter.ToString(Buf, j, 1);
}
Console.WriteLine("0x{0}", Mass_string);
Mass_string = "";
}
}
public static byte[] Length_Hex(long _Length)
{
byte[] Buf = { (byte)(_Length >> 0), (byte)(_Length >> 8), (byte)(_Length >> 16), (byte)(_Length >> 24) };
return Buf;
}
public static string Get_LPS(byte[] Buf, ref long J)
{
long B = BitConverter.ToUInt32(Buf.Take(4).ToArray(), 0);
byte[] Buf_Text = new byte[J];
Buf_Text = Buf.Skip(4).Take((int)(B)).ToArray();
J += B + 4;
return Encoding.GetEncoding("windows-1251").GetString(Buf_Text);
}
public static long Get_UL(byte[] Buf, ref long J)
{
J += 4;
return BitConverter.ToUInt32(Buf.Take(4).ToArray(), 0);
}
public void Add_Date_UL(long[] Buf)
{
byte[] temp;
int j;
if (Date == null)
{
temp = new byte[Buf.Length * 4];
j = 0;
}
else
{
temp = new byte[Date.Length + (Buf.Length * 4)];
Date.CopyTo(temp, 0);
j = Date.Length;
}
for (int i = 0; i < Buf.Length; i++)
{
Length_Hex(Buf[i]).CopyTo(temp, j);
j += 4;
}
Date = new byte[temp.Length];
temp.CopyTo(Date, 0);
}
public void Add_Date_LPS(string[] Buf)
{
int Length_LPS = 0;
for (int i = 0; i < Buf.Length; i++)
{
Length_LPS += Buf[i].Length + 4;
}
byte[] temp;
int j;
if (Date == null)
{
temp = new byte[Length_LPS];
j = 0;
}
else
{
temp = new byte[Date.Length + Length_LPS];
Date.CopyTo(temp, 0);
j = Date.Length;
}
for (int i = 0; i < Buf.Length; i++)
{
Length_Hex(Buf[i].Length).CopyTo(temp, j);
j += 4;
Encoding.GetEncoding("windows-1251").GetBytes(Buf[i]).CopyTo(temp, j);
j += Encoding.GetEncoding("windows-1251").GetBytes(Buf[i]).Length;
}
Date = new byte[temp.Length];
temp.CopyTo(Date, 0);
}
public mrim_packet_header(long _magic, long _proto, long _seq, long _msg,
long _dlen, long _from, long _fromport,
long _reserved_1, long _reserved_2, long _reserved_3, long _reserved_4)
{
magic = _magic;
proto = _proto;
seq = _seq;
msg = _msg;
dlen = _dlen;
from = _from;
fromport = _fromport;
reserved_1 = _reserved_1;
reserved_2 = _reserved_2;
reserved_3 = _reserved_3;
reserved_4 = _reserved_4;
User_Struct.Seq++;
}
public byte[] Generat_Packet()
{
if (Date != null)
dlen = Date.Length;
byte[] Buf = {(byte)(magic >> 0), (byte)(magic >> 8), (byte)(magic >> 16), (byte)(magic >> 24),
(byte)(proto >> 0), (byte)(proto >> 8), (byte)(proto >> 16), (byte)(proto >> 24),
(byte)(seq >> 0), (byte)(seq >> 8), (byte)(seq >> 16), (byte)(seq >> 24),
(byte)(msg >> 0), (byte)(msg >> 8), (byte)(msg >> 16), (byte)(msg >> 24),
(byte)(dlen >> 0), (byte)(dlen >> 8), (byte)(dlen >> 16), (byte)(dlen >> 24),
(byte)(from >> 0), (byte)(from >> 8), (byte)(from >> 16), (byte)(from >> 24),
(byte)(fromport >> 0), (byte)(fromport >> 8), (byte)(fromport >> 16), (byte)(fromport >> 24),
(byte)(reserved_1 >> 0), (byte)(reserved_1 >> 8), (byte)(reserved_1 >> 16), (byte)(reserved_1 >> 24),
(byte)(reserved_2 >> 0), (byte)(reserved_2 >> 8), (byte)(reserved_2 >> 16), (byte)(reserved_2 >> 24),
(byte)(reserved_3 >> 0), (byte)(reserved_3 >> 8), (byte)(reserved_3 >> 16), (byte)(reserved_3 >> 24),
(byte)(reserved_4 >> 0), (byte)(reserved_4 >> 8), (byte)(reserved_4 >> 16), (byte)(reserved_4 >> 24)};
if (Date != null)
{
byte[] Buf_Date = new byte[Date.Length + Buf.Length];
Buf.CopyTo(Buf_Date, 0);
Date.CopyTo(Buf_Date, 44);
return Buf_Date;
}
return Buf;
}
}
public class MRimClient
{
public Socket Sock;
private byte[] Buffer_Ansy = new byte[44];
#region ***Получает IPAdress к которому нужно подключиться***
/// <summary>
/// Получает IPAdress к которому нужно подключиться
/// </summary>
private int Get_IPAdress_Server()
{
string Buf = "";
try
{
TcpClient tc = new TcpClient("mrim.mail.ru", 2042);
byte[] buffer = new byte[19];
NetworkStream nss = tc.GetStream();
nss.Read(buffer, 0, 19);
Buf = Encoding.ASCII.GetString(buffer).Trim();
User_Struct.Server_IPAdress = Buf.Substring(0, Buf.IndexOf(":"));
User_Struct.Server_Port = int.Parse(Buf.Substring(Buf.IndexOf(":") + 1, Buf.Length - Buf.IndexOf(":") - 1));
return 0;
}
catch (SocketException)
{
return -1;
}
}
#endregion
#region ***Подключаемся к Серверу Mrim***
/// <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;
}
}
#endregion
#region ***Отправка СМС***
/// <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);
}
#endregion
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);
}
}
}
} |
|
Добавлено через 6 минут
Еще один более полный код, который на прямую работает с mrim протоколом на C# (код не мой, нашел где-то в просторах интернета на забуржуйском сайте):
| C# | 1
2
3
4
5
6
7
8
9
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Collections;
using System.Runtime.CompilerServices;
namespace mrim
{
#region ***Список Mrim_DNS***
struct Server_IP
{
public static string Server_1 = "mrim.mail.ru";
public static int Server_1_Port = 2042;
public static string Server_2 = "mrim.mail.ru";
public static int Server_2_Port = 443;
}
#endregion
#region ***User_Struct***
struct User_Struct
{
public static string Server_IPAdress = "";
public static int Server_Port = 0;
public static string Login = "";
public static string Password = "";
public static string Nick_Name = "";
public static string EMail_Total = "0";
public static string EMail_UnRead = "0";
public static int Ping_Time = 0;
public static int Seq = 1;
public static string User_Agent = "client=\"magent\" version=\"5.7\" build=\"3797\""; //Идентификатор клиента
public static string Error_String = "";
}
#endregion
#region ***Идентификаторы сообщений***
struct Msg
{
public const long CS_MAGIC = 0xDEADBEEF; // Клиентский Magic
public const long PROTO_VERSION = 0x00010015; // Версия протокола
public const long MRIM_CS_HELLO = 0x1001;
public const long MRIM_CS_HELLO_ACK = 0x1002;
public const long MRIM_CS_LOGIN2 = 0x1038;
public const long MRIM_CS_LOGOUT = 0x1013;
public const long LOGOUT_NO_RELOGIN_FLAG = 0x10;
public const long MRIM_CS_LOGIN_ACK = 0x1004;
public const long MRIM_CS_LOGIN_REJ = 0x1005;
public const long MRIM_CS_PING = 0x1006;
public const long MRIM_CS_USER_INFO = 0x1015;
public const long MRIM_CS_MESSAGE = 0x1008;
public const long MRIM_CS_MESSAGE_RECV = 0x1011;
public const long MRIM_CS_CONTACT_LIST2 = 0x1037;
public const long MESSAGE_FLAG_OFFLINE = 0x00000001;
public const long MESSAGE_FLAG_NORECV = 0x00000004;
public const long MESSAGE_FLAG_AUTHORIZE = 0x00000008;
public const long MESSAGE_FLAG_SYSTEM = 0x00302000;
public const long MESSAGE_FLAG_RTF = 0x00000080;
public const long MESSAGE_FLAG_CONTACT = 0x00200080;
public const long MESSAGE_FLAG_NOTIFY = 0x00200404;
public const long MESSAGE_FLAG_MULTICAST = 0x00001000;
public const long GET_CONTACTS_OK = 0x0000;
public const long GET_CONTACTS_ERROR = 0x0001;
public const string GET_CONTACTS_ERROR_Msg = "найденный контакт-лист некорректен";
public const long ET_CONTACTS_INTERR = 0x0002;
public const string ET_CONTACTS_INTERR_Msg = "произошла внутренняя ошибка";
public const long MRIM_CS_USER_STATUS = 0x100F; // S -> C
public const long STATUS_OFFLINE = 0x00000000;
public const long STATUS_ONLINE = 0x00000001;
public const long STATUS_AWAY = 0x00000002;
public const long STATUS_UNDETERMINATED = 0x00000003;
public const long STATUS_FLAG_INVISIBLE = 0x80000000;
public const long MRIM_CS_SMS = 0x1039;
public const long MRIM_SMS_GROUP = 0x67;
public const long MRIM_CS_SMS_ACK = 0x1040;
public const long MRIM_CS_SMS_SEND_OK = 0x2AAA;
public const long MRIM_CS_SMS_SEND_Error = 0x2AAC;
public const long MRIM_CS_MESSAGE_ACK = 0x1009;
public const long CONTACT_FLAG_GROUP = 0x02;
public const long CONTACT_FLAG_IGNORE = 0x10;
public const long CONTACT_FLAG_INVISIBLE = 0x04;
public const long CONTACT_FLAG_REMOVED = 0x01;
public const long CONTACT_FLAG_SHADOW = 0x20;
public const long CONTACT_FLAG_SMS = 0x100000;
public const long CONTACT_FLAG_VISIBLE = 0x08;
public const long CONTACT_INTFLAG_NOT_AUTHORIZED = 0x01;
public const long MRIM_CS_ADD_CONTACT = 0x1019;
public const long MRIM_CS_ADD_CONTACT_ACK = 0x101A;
public const long CONTACT_OPER_SUCCESS = 0x00;
public const string CONTACT_OPER_SUCCESS_Msg = "добавление произведено успешно";
public const long CONTACT_OPER_ERROR = 0x01;
public const string CONTACT_OPER_ERROR_Msg = "переданные данные были некорректны";
public const long CONTACT_OPER_INTERR = 0x02;
public const string CONTACT_OPER_INTERR_Msg = "при обработке запроса произошла внутренняя ошибка";
public const long CONTACT_OPER_NO_SUCH_USER = 0x03;
public const string CONTACT_OPER_NO_SUCH_USER_Msg = "добавляемого пользователя не существует в системе";
public const long CONTACT_OPER_INVALID_INFO = 0x04;
public const string CONTACT_OPER_INVALID_INFO_Msg = "некорректное имя пользователя";
public const long CONTACT_OPER_USER_EXISTS = 0x05;
public const string CONTACT_OPER_USER_EXISTS_Msg = "пользователь уже есть в контакт-листе";
public const long CONTACT_OPER_GROUP_LIMIT = 0x6;
public const string CONTACT_OPER_GROUP_LIMIT_Msg = "превышено максимально допустимое количество групп (20)";
public const long MRIM_CS_NEW_EMAIL = 0x1048;
public const long MRIM_CS_GET_MPOP_SESSION = 0x1024;
public const long MRIM_CS_MPOP_SESSION = 0x1025;
public const long MRIM_GET_SESSION_SUCCESS = 1;
}
#endregion
#region ***Class Пакет отправки/приёма данных***
class mrim_packet_header
{
public long magic; // Magic
public long proto; // Версия протокола
public long seq; // Sequence
public long msg; // Тип пакета
public long dlen; // Длина данных
public long from; // Адрес отправителя
public long fromport; // Порт отправителя
public long reserved_1; //
public long reserved_2; //
public long reserved_3; //
public long reserved_4; //
public byte[] Date;//
public static void Loger(byte[] Buf, int N)
{
string Mass_string = "";
for (int i = 1; i <= N / 4; i++)
{
for (int j = (i * 4) - 1; j > (i * 4) - 5; j--)
{
Mass_string += BitConverter.ToString(Buf, j, 1);
}
Console.WriteLine("0x{0}", Mass_string);
Mass_string = "";
}
}
public static byte[] Length_Hex(long _Length)
{
byte[] Buf = { (byte)(_Length >> 0), (byte)(_Length >> 8), (byte)(_Length >> 16), (byte)(_Length >> 24) };
return Buf;
}
public static string Get_LPS(byte[] Buf, ref long J)
{
long B = BitConverter.ToUInt32(Buf.Take(4).ToArray(), 0);
byte[] Buf_Text = new byte[J];
Buf_Text = Buf.Skip(4).Take((int)(B)).ToArray();
J += B + 4;
return Encoding.GetEncoding("windows-1251").GetString(Buf_Text);
}
public static long Get_UL(byte[] Buf, ref long J)
{
J += 4;
return BitConverter.ToUInt32(Buf.Take(4).ToArray(), 0);
}
public void Add_Date_UL(long[] Buf)
{
byte[] temp;
int j;
if (Date == null)
{
temp = new byte[Buf.Length * 4];
j = 0;
}
else
{
temp = new byte[Date.Length + (Buf.Length * 4)];
Date.CopyTo(temp, 0);
j = Date.Length;
}
for (int i = 0; i < Buf.Length; i++)
{
Length_Hex(Buf[i]).CopyTo(temp, j);
j += 4;
}
Date = new byte[temp.Length];
temp.CopyTo(Date, 0);
}
public void Add_Date_LPS(string[] Buf)
{
int Length_LPS = 0;
for (int i = 0; i < Buf.Length; i++)
{
Length_LPS += Buf[i].Length + 4;
}
byte[] temp;
int j;
if (Date == null)
{
temp = new byte[Length_LPS];
j = 0;
}
else
{
temp = new byte[Date.Length + Length_LPS];
Date.CopyTo(temp, 0);
j = Date.Length;
}
for (int i = 0; i < Buf.Length; i++)
{
Length_Hex(Buf[i].Length).CopyTo(temp, j);
j += 4;
Encoding.GetEncoding("windows-1251").GetBytes(Buf[i]).CopyTo(temp, j);
j += Encoding.GetEncoding("windows-1251").GetBytes(Buf[i]).Length;
}
Date = new byte[temp.Length];
temp.CopyTo(Date, 0);
}
public mrim_packet_header(long _magic, long _proto, long _seq, long _msg,
long _dlen, long _from, long _fromport,
long _reserved_1, long _reserved_2, long _reserved_3, long _reserved_4)
{
magic = _magic;
proto = _proto;
seq = _seq;
msg = _msg;
dlen = _dlen;
from = _from;
fromport = _fromport;
reserved_1 = _reserved_1;
reserved_2 = _reserved_2;
reserved_3 = _reserved_3;
reserved_4 = _reserved_4;
User_Struct.Seq++;
}
public byte[] Generat_Packet()
{
if (Date != null)
dlen = Date.Length;
byte[] Buf = {(byte)(magic >> 0), (byte)(magic >> 8), (byte)(magic >> 16), (byte)(magic >> 24),
(byte)(proto >> 0), (byte)(proto >> 8), (byte)(proto >> 16), (byte)(proto >> 24),
(byte)(seq >> 0), (byte)(seq >> 8), (byte)(seq >> 16), (byte)(seq >> 24),
(byte)(msg >> 0), (byte)(msg >> 8), (byte)(msg >> 16), (byte)(msg >> 24),
(byte)(dlen >> 0), (byte)(dlen >> 8), (byte)(dlen >> 16), (byte)(dlen >> 24),
(byte)(from >> 0), (byte)(from >> 8), (byte)(from >> 16), (byte)(from >> 24),
(byte)(fromport >> 0), (byte)(fromport >> 8), (byte)(fromport >> 16), (byte)(fromport >> 24),
(byte)(reserved_1 >> 0), (byte)(reserved_1 >> 8), (byte)(reserved_1 >> 16), (byte)(reserved_1 >> 24),
(byte)(reserved_2 >> 0), (byte)(reserved_2 >> 8), (byte)(reserved_2 >> 16), (byte)(reserved_2 >> 24),
(byte)(reserved_3 >> 0), (byte)(reserved_3 >> 8), (byte)(reserved_3 >> 16), (byte)(reserved_3 >> 24),
(byte)(reserved_4 >> 0), (byte)(reserved_4 >> 8), (byte)(reserved_4 >> 16), (byte)(reserved_4 >> 24)};
if (Date != null)
{
byte[] Buf_Date = new byte[Date.Length + Buf.Length];
Buf.CopyTo(Buf_Date, 0);
Date.CopyTo(Buf_Date, 44);
return Buf_Date;
}
return Buf;
}
}
#endregion
class Mrim_Class
{
public Socket Sock;
private byte[] Buffer_Ansy = new byte[44];
#region ***Делегаты и события***
public delegate void Complite_Connect_Delegate();
/// <summary>
/// Вызывает при удачном подключении
/// </summary>
public event Complite_Connect_Delegate Complite_Connect_Method;
public delegate void Error_Connect_Delegate(string Error_msg);
/// <summary>
/// Вызывает при ошибке
/// </summary>
public event Error_Connect_Delegate Error_Connect_Method;
public delegate void EMail_Info_Delegate(string Total, string UnRead);
/// <summary>
/// Вызывает при получении информации о каличествах писем в почтовом ящике
/// </summary>
public event EMail_Info_Delegate EMail_Info_Method;
public delegate void Begin_Update_GroupList_Delegate(long ID_Group, string Name_Group);
/// <summary>
/// Вызывает при пришедших данных о группах
/// </summary>
public event Begin_Update_GroupList_Delegate Begin_Update_GroupList_Method;
public delegate void Begin_Update_ContactList_Delegate(long Flag, long ID_Group, long Status, string _Mail, string _Nick);
/// <summary>
/// Вызывает при пришедших данных о ContactList
/// </summary>
public event Begin_Update_ContactList_Delegate Begin_Update_ContactList_Method;
public delegate void Msg_NOTIFY_Delegate(string _Mail);
/// <summary>
/// Вызывает если кто то вам пишет сообщение
/// </summary>
public event Msg_NOTIFY_Delegate Msg_NOTIFY_Method;
public delegate void Msg_Response_Contact_Delegate(string _Mail, string _Text);
/// <summary>
/// Вызывается при получения сообщение от контакта
/// </summary>
public event Msg_Response_Contact_Delegate Msg_Response_Contact_Method;
public delegate void Msg_Response_System_Delegate(string _Mail, string _Text);
/// <summary>
/// Вызывается при получения сообщение от системы
/// </summary>
public event Msg_Response_System_Delegate Msg_Response_System_Method;
public delegate void Result_Operation_Delegate(long _Flag, string _Text);
/// <summary>
/// Вызывается при получения результата выполняемых действий
/// </summary>
public event Result_Operation_Delegate Result_Operation_Method;
public delegate void Logout_Delegate(long _Flag);
/// <summary>
/// Вызывается при разрыве соединение сервером
/// </summary>
public event Logout_Delegate Logout_Method;
public delegate void New_Email_Delegate(long UnRead, string Respone_Email, string Theme);
/// <summary>
/// Вызывается при приходе новой почты
/// </summary>
public event New_Email_Delegate New_Email_Method;
public delegate void Response_MPOP_SESSION_Delegate(string Key);
/// <summary>
/// Вызывается при получение ключа для WEB авторизации
/// </summary>
public event Response_MPOP_SESSION_Delegate Response_MPOP_SESSION_Method;
#endregion
#region ***Получает IPAdress к которому нужно подключиться***
/// <summary>
/// Получает IPAdress к которому нужно подключиться
/// </summary>
private int Get_IPAdress_Server()
{
string Buf = "";
try
{
TcpClient tc = new TcpClient(Server_IP.Server_1, Server_IP.Server_1_Port);
byte[] buffer = new byte[19];
NetworkStream nss = tc.GetStream();
nss.Read(buffer, 0, 19);
Buf = Encoding.ASCII.GetString(buffer).Trim();
User_Struct.Server_IPAdress = Buf.Substring(0, Buf.IndexOf(":"));
User_Struct.Server_Port = int.Parse(Buf.Substring(Buf.IndexOf(":") + 1, Buf.Length - Buf.IndexOf(":") - 1));
return 0;
}
catch (SocketException)
{
}
try
{
TcpClient tc = new TcpClient(Server_IP.Server_2, Server_IP.Server_2_Port);
byte[] buffer = new byte[19];
NetworkStream nss = tc.GetStream();
nss.Read(buffer, 0, 19);
Buf = Encoding.ASCII.GetString(buffer).Trim();
User_Struct.Server_IPAdress = Buf.Substring(0, Buf.IndexOf(":"));
User_Struct.Server_Port = int.Parse(Buf.Substring(Buf.IndexOf(":") + 1, Buf.Length - Buf.IndexOf(":") - 1));
return 0;
}
catch (SocketException)
{
return -1;
}
}
#endregion
#region ***Подключаемся к Серверу Mrim***
/// <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)
{
if (Error_Connect_Method != null) Error_Connect_Method("Серевер недоступен!");
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).ToArra y(), 0) != Msg.MRIM_CS_HELLO_ACK)
{
Sock.Close();
if (Error_Connect_Method != null) Error_Connect_Method("Серевер недоступен!");
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) * 1000;
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, 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_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).ToArra y(), 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);
Error_Connect_Method(Encoding.GetEncoding("windows-1251").GetString(Date));
return -4;
}
if (Complite_Connect_Method != null) Complite_Connect_Method();
Sock.Receive(Buf = new byte[44]);
if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArra y(), 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)
{
J = BitConverter.ToUInt32(new byte[4] { Date[M], Date[J + 1], Date[J + 2], Date[J + 3] }, 0);
M += 4;
Buf_Text = new byte[J];
Buf_Text = Date.Skip((int)(M)).Take((int)(J)).ToArray();
M += J;
J = M;
switch (Encoding.GetEncoding("windows-1251").GetString(Buf_Text))
{
case "MESSAGES.TOTAL":
J = BitConverter.ToUInt32(new byte[4] { Date[M], Date[J + 1], Date[J + 2], Date[J + 3] }, 0);
M += 4;
Buf_Text = new byte[J];
User_Struct.EMail_Total = Encoding.GetEncoding("windows-1251").GetString(Date.Skip((int)(M)).Take((int)(J) ).ToArray());
break;
case "MESSAGES.UNREAD":
J = BitConverter.ToUInt32(new byte[4] { Date[M], Date[J + 1], Date[J + 2], Date[J + 3] }, 0);
M += 4;
Buf_Text = new byte[J];
User_Struct.EMail_UnRead = Encoding.GetEncoding("windows-1251").GetString(Date.Skip((int)(M)).Take((int)(J) ).ToArray());
break;
case "MRIM.NICKNAME":
J = BitConverter.ToUInt32(new byte[4] { Date[M], Date[J + 1], Date[J + 2], Date[J + 3] }, 0);
M += 4;
Buf_Text = new byte[J];
User_Struct.Nick_Name = Encoding.GetEncoding("windows-1251").GetString(Date.Skip((int)(M)).Take((int)(J) ).ToArray());
break;
default:
J = BitConverter.ToUInt32(new byte[4] { Date[M], Date[J + 1], Date[J + 2], Date[J + 3] }, 0);
M += 4;
Buf_Text = new byte[J];
User_Struct.Nick_Name = Encoding.GetEncoding("windows-1251").GetString(Date.Skip((int)(M)).Take((int)(J) ).ToArray());
break;
}
M += J;
J = M;
}
if (EMail_Info_Method != null) EMail_Info_Method(User_Struct.EMail_Total, User_Struct.EMail_UnRead);
}
Receive();
return 0;
}
catch (SocketException e)
{
Sock.Close();
if (Error_Connect_Method != null) Error_Connect_Method(e.Message);
return -100;
}
}
#endregion
#region ***Добавляем нового СМС контакта***
/// <summary>
/// Добавляем нового СМС контакта
/// </summary>
public void Add_SMS_Contact(string _Name, string _Phone)
{
mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_ADD_CONTACT, 0, 0, 0, 0, 0, 0, 0);
Pack.Add_Date_UL(new long[] { Msg.CONTACT_FLAG_SMS });
Pack.Add_Date_UL(new long[] { Msg.MRIM_SMS_GROUP });
Pack.Add_Date_LPS(new string[] { "phone", _Name, _Phone, "", "", "" });
byte[] Add_Contact_Send = Pack.Generat_Packet();
Console.WriteLine(BitConverter.ToString(Add_Contac t_Send));
Sock.Send(Add_Contact_Send);
}
#endregion
#region ***Отправка СМС***
/// <summary>
/// Отправка СМС
/// </summary>
public void Send_Sms(string _Phone, string _Text)
{
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);
}
#endregion
#region ***Запрос на получение ключа для WEB авторизации***
/// <summary>
/// Запрос на получение ключа для WEB авторизации
/// </summary>
public void GET_MPOP_SESSION()
{
mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_GET_MPOP_SESSION, 0, 0, 0, 0, 0, 0, 0);
byte[] MPOP_SESSION = Pack.Generat_Packet();
Sock.Send(MPOP_SESSION);
}
#endregion
private void Receive()
{
try
{
Sock.BeginReceive(Buffer_Ansy, 0, 44, 0, new AsyncCallback(ReceiveCallback), Sock);
}
catch (Exception e)
{
Sock.Close();
if (Error_Connect_Method != null) Error_Connect_Method(e.Message);
}
}
private void ReceiveCallback(IAsyncResult ar)
{
try
{
Socket Client = (Socket)ar.AsyncState;
int bytesRead = Client.EndReceive(ar);
if (bytesRead > 0)
{
mrim_packet_header.Loger(Buffer_Ansy, 44);
if (BitConverter.ToUInt32(Buffer_Ansy.Take(4).ToArray (), 0) == Msg.CS_MAGIC)
{
long Cmd = BitConverter.ToInt32(Buffer_Ansy.Skip(12).Take(4). ToArray(), 0);
if (BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4) .ToArray(), 0) > 0)
{
switch (Cmd)
{
case Msg.MRIM_CS_CONTACT_LIST2:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
Get_Contact_List(Buffer_Ansy);
break;
case Msg.MRIM_CS_MESSAGE_ACK:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
Response_Msg(Buffer_Ansy);
break;
case Msg.MRIM_CS_ADD_CONTACT_ACK:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
Add_SMS_Contact_ACK(Buffer_Ansy);
break;
case Msg.MRIM_CS_LOGOUT:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
Logout(Buffer_Ansy);
break;
case Msg.MRIM_CS_NEW_EMAIL:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
New_Mail(Buffer_Ansy);
break;
case Msg.MRIM_CS_MPOP_SESSION:
Buffer_Ansy = new byte[BitConverter.ToInt32(Buffer_Ansy.Skip(16).Take(4). ToArray(), 0)];
Client.Receive(Buffer_Ansy);
Response_MPOP_SESSION(Buffer_Ansy);
break;
default:
//Console.WriteLine(Cmd);
break;
}
}
}
Buffer_Ansy = new byte[44];
Client.BeginReceive(Buffer_Ansy, 0, 44, 0,
new AsyncCallback(ReceiveCallback), Sock);
}
}
catch (Exception e)
{
Sock.Close();
if (Error_Connect_Method != null) Error_Connect_Method(e.Message);
}
}
private void Response_MPOP_SESSION(byte[] Buf)
{
long M = 0;
if (mrim_packet_header.Get_UL(Buf, ref M) == Msg.MRIM_GET_SESSION_SUCCESS)
{
if (Response_MPOP_SESSION_Method != null)
Response_MPOP_SESSION_Method(mrim_packet_header.Ge t_LPS(Buf.Skip((int)(M)).ToArray(), ref M));
}
else
{
if (Response_MPOP_SESSION_Method != null)
Response_MPOP_SESSION_Method("");
}
}
private void New_Mail(byte[] Buf)
{
long M = 0;
if (New_Email_Method != null)
New_Email_Method(mrim_packet_header.Get_UL(Buf, ref M),
mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M),
mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M));
}
private void Logout(byte[] Buf)
{
long M = 0;
if (Logout_Method == null) return;
switch (mrim_packet_header.Get_UL(Buf, ref M))
{
case Msg.LOGOUT_NO_RELOGIN_FLAG:
Logout_Method(Msg.LOGOUT_NO_RELOGIN_FLAG);
break;
default:
Logout_Method(0x00);
break;
}
}
private void Add_SMS_Contact_ACK(byte[] Buf)
{
long M = 0;
if (Result_Operation_Method == null) return;
switch (mrim_packet_header.Get_UL(Buf, ref M))
{
case Msg.CONTACT_OPER_ERROR:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_ERROR_Msg);
break;
case Msg.CONTACT_OPER_GROUP_LIMIT:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_GROUP_LIMIT_Msg);
break;
case Msg.CONTACT_OPER_INTERR:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_INTERR_Msg);
break;
case Msg.CONTACT_OPER_INVALID_INFO:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_INVALID_INFO_Msg);
break;
case Msg.CONTACT_OPER_NO_SUCH_USER:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_NO_SUCH_USER_Msg);
break;
case Msg.CONTACT_OPER_SUCCESS:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_SUCCESS_Msg);
break;
case Msg.CONTACT_OPER_USER_EXISTS:
Result_Operation_Method(Msg.MRIM_CS_ADD_CONTACT_AC K, Msg.CONTACT_OPER_USER_EXISTS_Msg);
break;
default:
Result_Operation_Method(0x00, Msg.CONTACT_OPER_USER_EXISTS_Msg);
break;
}
}
private void Response_Msg(byte[] Buf)
{
long M = 0;
long[] UL = new long[64];
string[] LPS = new string[64];
UL[0] = mrim_packet_header.Get_UL(Buf, ref M);
mrim_packet_header.Loger(Buf, Buf.Length);
UL[1] = mrim_packet_header.Get_UL(Buf.Skip((int)(M)).ToArr ay(), ref M);
LPS[0] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);
switch (UL[1])
{
case Msg.MESSAGE_FLAG_CONTACT:
LPS[1] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);
Response_Msg_RECV(LPS[0], UL[0]);
if (Msg_Response_Contact_Method != null)
Msg_Response_Contact_Method(LPS[0], LPS[1]);
break;
case Msg.MESSAGE_FLAG_NOTIFY:
if (Msg_NOTIFY_Method != null)
Msg_NOTIFY_Method(LPS[0]);
break;
case Msg.MESSAGE_FLAG_SYSTEM:
LPS[1] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);
if (Msg_Response_Contact_Method != null)
Msg_Response_Contact_Method(LPS[0], LPS[1]);
break;
}
}
private void Response_Msg_RECV(string from, long SEO)
{
mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, User_Struct.Seq, Msg.MRIM_CS_MESSAGE_RECV, 0, 0, 0, 0, 0, 0, 0);
Pack.Add_Date_LPS(new string[] { from });
Pack.Add_Date_UL(new long[] { SEO });
byte[] MESSAGE_ACK = Pack.Generat_Packet();
Sock.Send(MESSAGE_ACK);
}
private void Get_Contact_List(byte[] Buf)
{
long M = 0;
long[] UL = new long[64];
string[] LPS = new string[64];
UL[0] = BitConverter.ToUInt32(Buf.Take(4).ToArray(), 0);
UL[1] = BitConverter.ToUInt32(Buf.Skip(4).Take(4).ToArray( ), 0);
LPS[1] = Encoding.GetEncoding("windows-1251").GetString(Buf.Skip(18).Take(7).ToArray()).T rim();
switch (UL[0])
{
case Msg.GET_CONTACTS_OK:
M = 25;
for (int i = 1; i <= UL[1]; i++)
{
UL[2] = BitConverter.ToInt32(new byte[] { Buf[M + 3], Buf[M + 2], Buf[M + 1], 0x00 }, 0);
LPS[2] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M + 4)).ToArray(), ref M);
M += 4;
if (Begin_Update_GroupList_Method != null) Begin_Update_GroupList_Method(UL[2], LPS[2]);
}
while (Buf.Length > M)
{
UL[2] = mrim_packet_header.Get_UL(Buf.Skip((int)(M)).ToArr ay(), ref M);
UL[3] = mrim_packet_header.Get_UL(Buf.Skip((int)(M)).ToArr ay(), ref M);
LPS[2] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);//Почта
if (LPS[2] == "")
break;
LPS[3] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);//Ник
M += 4;//Пропуск хрени
UL[5] = mrim_packet_header.Get_UL(Buf.Skip((int)(M)).ToArr ay(), ref M);
LPS[4] = mrim_packet_header.Get_LPS(Buf.Skip((int)(M)).ToAr ray(), ref M);//Ник
Console.WriteLine(LPS[2]);
Console.WriteLine(LPS[3]);
Console.WriteLine(LPS[4]);
Console.WriteLine("-----");
if (Begin_Update_ContactList_Method != null)
Begin_Update_ContactList_Method(UL[2], UL[3], UL[5], LPS[2], LPS[3]);
}
break;
case Msg.GET_CONTACTS_ERROR:
if (Error_Connect_Method != null) Error_Connect_Method(Msg.GET_CONTACTS_ERROR_Msg);
break;
case Msg.ET_CONTACTS_INTERR:
if (Error_Connect_Method != null) Error_Connect_Method(Msg.ET_CONTACTS_INTERR_Msg);
break;
}
}
private void Send_Ping(object Sender, EventArgs args)
{
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);
}
}
}
} |
|
Вот таким образом можно использовать:
| C# | 1
2
3
4
5
6
7
8
9
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
62
63
64
65
66
67
68
69
70
71
| mrim.Mrim_Class MrimClient = new mrim.Mrim_Class();
MrimClient.Complite_Connect_Method += new mrim.Mrim_Class.Complite_Connect_Delegate(OnConnec t);
MrimClient.Error_Connect_Method += new mrim.Mrim_Class.Error_Connect_Delegate(OnErrorConn ect);
MrimClient.EMail_Info_Method += new mrim.Mrim_Class.EMail_Info_Delegate(OnEmail_Count) ;
MrimClient.Begin_Update_GroupList_Method += new mrim.Mrim_Class.Begin_Update_GroupList_Delegate(On Begin_ContactList);
MrimClient.Msg_NOTIFY_Method += new mrim.Mrim_Class.Msg_NOTIFY_Delegate(OnNotify);
MrimClient.Msg_Response_Contact_Method += new mrim.Mrim_Class.Msg_Response_Contact_Delegate(OnMs g);
MrimClient.Msg_Response_System_Method += new mrim.Mrim_Class.Msg_Response_System_Delegate(OnMsg );
MrimClient.Result_Operation_Method += new mrim.Mrim_Class.Result_Operation_Delegate(Result_O per);
MrimClient.Logout_Method += new mrim.Mrim_Class.Logout_Delegate(Logout);
MrimClient.New_Email_Method += new mrim.Mrim_Class.New_Email_Delegate(NewMail);
MrimClient.Response_MPOP_SESSION_Method += new mrim.Mrim_Class.Response_MPOP_SESSION_Delegate(Mri mClient_Response_MPOP_SESSION_Method);
Console.WriteLine("[~] Connecting...");
MrimClient.Login("Kseni_r@mail.ru", "Ab12345", mrim.Msg.STATUS_ONLINE);
public static void MrimClient_Response_MPOP_SESSION_Method(string Key)
{
if (Key != "")
MessageBox.Show("[*] Ключ авторизации {0}", Key);
else
MessageBox.Show("[!] Неудалось получить Клич авторизации");
}
public static void NewMail(long _UnRead, string _Author, string _Theme)
{
MessageBox.Show("[!] Новое пиьсмо:");
MessageBox.Show("[!] Автор: {0}", _Author);
MessageBox.Show("[!] Тема: {0}", _Theme);
Console.WriteLine("[!] Непрочитано: {0}", _UnRead);
}
public static void Logout(long _Flag)
{
if (_Flag == mrim.Msg.LOGOUT_NO_RELOGIN_FLAG)
Console.WriteLine("[!] Ак используеться на другом клиента");
else
Console.WriteLine("[!] Сервер разорвал соединение");
}
public static void Result_Oper(long _Type, string Msg)
{
Console.WriteLine("[!] {0}", Msg);
}
public static void OnConnect()
{
Console.WriteLine("[+] Connected to {0}:{1}", mrim.User_Struct.Server_IPAdress, mrim.User_Struct.Server_Port);
}
public static void OnErrorConnect(string Error_msg)
{
Console.WriteLine("[!] {0}", Error_msg);
}
public static void OnEmail_Count(string Total, string UnRead)
{
Console.WriteLine("[+] Total Email: {0}", Total);
Console.WriteLine("[+] UnRead Email: {0}", UnRead);
}
public static void OnBegin_ContactList(long ID, string Name)
{
Console.WriteLine("- {0} - ({1})", Name, ID);
}
public static void OnNotify(string _Mail)
{
Console.WriteLine("Вам пишет: {0}", _Mail);
}
public static void OnMsg(string _Mail, string _Text)
{
Console.WriteLine("--------------------------------");
Console.WriteLine("Новое сообещние от: {0}", _Mail);
Console.WriteLine(_Text);
Console.WriteLine("--------------------------------");
} |
|
1
|