📄 callme.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Client;
using Imps.Client.Utils;
using Imps.Utils;
using System;
using System.Security.Cryptography;
using System.Text;
public static class CallMe
{
private static CallMeInfo[] _callMeInfoes = new CallMeInfo[_maxCallMeCount];
private static MainForm _mainForm = null;
private static readonly int _maxCallMeCount = 3;
private static int _oldestIndex = 0;
private static bool _userAccountFilled = false;
public static void InitCallMe(MainForm mainForm)
{
_mainForm = mainForm;
GlobalTimer.Register(new EventHandler(CallMe.OnCallMeTimer), 2);
}
public static void OnCallMeTimer(object sender, EventArgs e)
{
try
{
GlobalTimer.Unregister(new EventHandler(CallMe.OnCallMeTimer));
if (_mainForm != null)
{
UserAccountStatus status;
try
{
status = _mainForm.AccountManager.CurrentUser.Status;
}
catch (Exception exception)
{
ClientLogger.WriteException("CallME", exception);
return;
}
if (status == UserAccountStatus.Logon)
{
for (int i = 0; i < _callMeInfoes.Length; i++)
{
if ((_callMeInfoes[i] != null) && _callMeInfoes[i].IsValid())
{
if ((DateTime.Now - _callMeInfoes[i].CallMeTime) >= new TimeSpan(0, 0, 0, 600))
{
_callMeInfoes[i].Clear();
}
else if (_callMeInfoes[i].Processed)
{
if ((DateTime.Now - _callMeInfoes[i].CallMeTime) >= new TimeSpan(0, 0, 0, 0, 0xbb8))
{
_callMeInfoes[i].Clear();
}
}
else
{
_mainForm.ConversationManager.StartStrangerConversation(_mainForm, _callMeInfoes[i].Uri);
_callMeInfoes[i].Processed = true;
if (_mainForm.AccountManager.CurrentUser.MobileNo != _callMeInfoes[i].MobileNum)
{
_mainForm.UnifiedMessageBox.ShowInfo(_mainForm, "您客户端登录的账号与网站登录的不一致,请确认登录PC客户端的用户身份。");
}
}
}
}
}
else if (((status == UserAccountStatus.None) || (status == UserAccountStatus.Logoff)) && ((!_mainForm.AccountManager.CurrentUser.AutoLogin && !_userAccountFilled) && ((_oldestIndex >= 0) && (_oldestIndex <= (_callMeInfoes.Length - 1)))))
{
CallMeInfo info = PreCallMeInfo(_oldestIndex);
if (info != null)
{
((EntryPointControl) _mainForm.AccountManager.EntryPointControl).CurrentId = info.MobileNum;
_userAccountFilled = true;
}
}
}
}
finally
{
GlobalTimer.Register(new EventHandler(CallMe.OnCallMeTimer), 2);
}
}
public static int ParseCallMeParams(string callMeParams)
{
try
{
string text7;
string text8;
DateTime now = DateTime.Now;
CallMeInfo info = PreCallMeInfo(_oldestIndex);
if (((info != null) && info.IsValid()) && ((now - info.CallMeTime) < new TimeSpan(0, 0, 0, 0, 0xbb8)))
{
return 1;
}
int length = callMeParams.IndexOf(CallMeKeyword.Char.Colon);
if ((-1 == length) || (length == (callMeParams.Length - 1)))
{
throw new ArgumentException(callMeParams);
}
string paramName = callMeParams.Substring(0, length);
if (((text7 = paramName) == null) || (text7 != "fetion"))
{
throw new ArgumentException("unknown protocol", paramName);
}
int index = callMeParams.IndexOf(CallMeKeyword.Char.QuestionMark);
if ((-1 == index) || (index == (callMeParams.Length - 1)))
{
throw new ArgumentException(callMeParams);
}
string text2 = callMeParams.Substring(length + 1, index - (length + 1));
if (((text8 = text2) == null) || (text8 != "chat"))
{
throw new ArgumentException("unknown command", text2);
}
int num3 = callMeParams.IndexOf(CallMeKeyword.ParamCheckMark);
if ((-1 == num3) || (num3 == (callMeParams.Length - CallMeKeyword.ParamCheckMark.Length)))
{
throw new ArgumentException(callMeParams);
}
string text3 = callMeParams.Substring(num3 + CallMeKeyword.ParamCheckMark.Length);
string s = "FetionCmd(" + callMeParams.Substring(0, num3) + ")";
MD5 md = new MD5CryptoServiceProvider();
md.Initialize();
if (!Convert.ToBase64String(md.ComputeHash(Encoding.Default.GetBytes(s))).Equals(text3))
{
throw new ArgumentException("invalid parameters!", callMeParams);
}
if (_callMeInfoes[_oldestIndex] == null)
{
_callMeInfoes[_oldestIndex] = new CallMeInfo();
}
_callMeInfoes[_oldestIndex].Protocol = paramName;
_callMeInfoes[_oldestIndex].Cmd = text2;
_callMeInfoes[_oldestIndex].CallMeTime = now;
_callMeInfoes[_oldestIndex].Processed = false;
string[] textArray = callMeParams.Substring(index + 1, num3 - (index + 1)).Split(new char[] { CallMeKeyword.Char.ParamDelimiter });
for (int i = 0; i < textArray.Length; i++)
{
int num5 = textArray[i].IndexOf(CallMeKeyword.Char.NameValueDelimiter);
if ((-1 == num5) || (num5 == (textArray[i].Length - 1)))
{
throw new ArgumentException("invalid name-value pairs!", textArray[i]);
}
string text5 = textArray[i].Substring(0, num5);
string text6 = textArray[i].Substring(num5 + 1);
switch (text5)
{
case "uri":
_callMeInfoes[_oldestIndex].Uri = text6;
break;
case "mobile":
_callMeInfoes[_oldestIndex].MobileNum = text6;
break;
default:
throw new ArgumentException("unknown parameter name!", text5);
}
}
if (_callMeInfoes[_oldestIndex].IsValid())
{
try
{
UserAccountStatus status = _mainForm.AccountManager.CurrentUser.Status;
if (((status == UserAccountStatus.None) || (status == UserAccountStatus.Logoff)) && !_mainForm.AccountManager.CurrentUser.AutoLogin)
{
((EntryPointControl) _mainForm.AccountManager.EntryPointControl).CurrentId = _callMeInfoes[_oldestIndex].MobileNum;
_userAccountFilled = true;
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
if (_oldestIndex == (_callMeInfoes.Length - 1))
{
_oldestIndex = 0;
}
else
{
_oldestIndex++;
}
}
else
{
_callMeInfoes[_oldestIndex].Clear();
throw new ArgumentException("invalid parameters!", callMeParams);
}
return 0;
}
catch (Exception exception2)
{
ClientLogger.WriteException(exception2);
return 2;
}
}
private static CallMeInfo PreCallMeInfo(int currIndex)
{
int index = -1;
CallMeInfo info = null;
if ((currIndex < 0) && (currIndex > (_callMeInfoes.Length - 1)))
{
throw new ArgumentOutOfRangeException("currIndex");
}
if (currIndex == 0)
{
index = _callMeInfoes.Length - 1;
}
else
{
index = currIndex - 1;
}
info = _callMeInfoes[index];
if ((info != null) && info.IsValid())
{
return info;
}
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -