www.pudn.com > Fetion.rar > 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 str7;
string str8;
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 index = callMeParams.IndexOf(CallMeKeyword.Char.Colon);
if ((-1 == index) || (index == (callMeParams.Length - 1)))
{
throw new ArgumentException(callMeParams);
}
string paramName = callMeParams.Substring(0, index);
if (((str7 = paramName) == null) || (str7 != "fetion"))
{
throw new ArgumentException("unknown protocol", paramName);
}
int num2 = callMeParams.IndexOf(CallMeKeyword.Char.QuestionMark);
if ((-1 == num2) || (num2 == (callMeParams.Length - 1)))
{
throw new ArgumentException(callMeParams);
}
string str2 = callMeParams.Substring(index + 1, num2 - (index + 1));
if (((str8 = str2) == null) || (str8 != "chat"))
{
throw new ArgumentException("unknown command", str2);
}
int length = callMeParams.IndexOf(CallMeKeyword.ParamCheckMark);
if ((-1 == length) || (length == (callMeParams.Length - CallMeKeyword.ParamCheckMark.Length)))
{
throw new ArgumentException(callMeParams);
}
string str3 = callMeParams.Substring(length + CallMeKeyword.ParamCheckMark.Length);
string s = "FetionCmd(" + callMeParams.Substring(0, length) + ")";
MD5 md = new MD5CryptoServiceProvider();
md.Initialize();
if (!Convert.ToBase64String(md.ComputeHash(Encoding.Default.GetBytes(s))).Equals(str3))
{
throw new ArgumentException("invalid parameters!", callMeParams);
}
if (_callMeInfoes[_oldestIndex] == null)
{
_callMeInfoes[_oldestIndex] = new CallMeInfo();
}
_callMeInfoes[_oldestIndex].Protocol = paramName;
_callMeInfoes[_oldestIndex].Cmd = str2;
_callMeInfoes[_oldestIndex].CallMeTime = now;
_callMeInfoes[_oldestIndex].Processed = false;
string[] strArray = callMeParams.Substring(num2 + 1, length - (num2 + 1)).Split(new char[] { CallMeKeyword.Char.ParamDelimiter });
for (int i = 0; i < strArray.Length; i++)
{
int num5 = strArray[i].IndexOf(CallMeKeyword.Char.NameValueDelimiter);
if ((-1 == num5) || (num5 == (strArray[i].Length - 1)))
{
throw new ArgumentException("invalid name-value pairs!", strArray[i]);
}
string str5 = strArray[i].Substring(0, num5);
string str6 = strArray[i].Substring(num5 + 1);
string str9 = str5;
if (str9 == null)
{
goto Label_02BF;
}
if (!(str9 == "uri"))
{
if (str9 == "mobile")
{
goto Label_02AB;
}
goto Label_02BF;
}
_callMeInfoes[_oldestIndex].Uri = str6;
continue;
Label_02AB:
_callMeInfoes[_oldestIndex].MobileNum = str6;
continue;
Label_02BF:
throw new ArgumentException("unknown parameter name!", str5);
}
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;
}
}
}