/// <summary> /// 连接 /// </summary> public async Task ConnectAsync() { //清理 Close(); cts = new CancellationTokenSource(); var token = cts.Token; var stream = await InnerConnectAsync(); IsConnected = true; //初始化网络 InitQpPackageHandler_Stream(stream); //开始读取其他数据包 BeginReadPackage(token); var repConnect = await SendCommand(new Commands.Connect.Request() { InstructionIds = Options.InstructionSet.Select(t => t.Id).ToArray() }); //如果服务端使用的缓存大小与客户端不同,则设置缓存大小为与服务端同样的大小 if (BufferSize != repConnect.BufferSize) { ChangeBufferSize(repConnect.BufferSize); } var repAuth = await SendCommand(new Commands.Authenticate.Request() { Answer = CryptographyUtils.ComputeMD5Hash(repConnect.Question + Options.Password) }); var repHandShake = await SendCommand(new Commands.HandShake.Request() { EnableCompress = Options.EnableCompress, EnableEncrypt = Options.EnableEncrypt, TransportTimeout = Options.TransportTimeout }, 5000, () => { Options.OnAuthPassed(); }); //开始心跳 if (Options.HeartBeatInterval > 0) { //定时发送心跳包 BeginHeartBeat(token); } }
public string CalculatePlanetRewardChecksum(Planet currentPlanet) { List <PlanetLootEntryVO> featuredLootEntriesForPlanet = Service.Get <InventoryCrateRewardController>().GetFeaturedLootEntriesForPlanet(currentPlanet); featuredLootEntriesForPlanet.Sort(new Comparison <PlanetLootEntryVO>(this.SortFeaturedLootEntries)); StringBuilder stringBuilder = new StringBuilder(); int i = 0; int count = featuredLootEntriesForPlanet.Count; while (i < count) { stringBuilder.Append(featuredLootEntriesForPlanet[i].Uid); i++; } return(CryptographyUtils.ComputeMD5Hash(stringBuilder.ToString())); }
public QpChannel(QpChannelOptions options) { this.options = options; ChangeBufferSize(BufferSize); passwordMd5Buffer = CryptographyUtils.ComputeMD5Hash(Encoding.UTF8.GetBytes(options.Password)).Take(8).ToArray(); enc = des.CreateEncryptor(passwordMd5Buffer, passwordMd5Buffer); dec = des.CreateDecryptor(passwordMd5Buffer, passwordMd5Buffer); foreach (var instructionSet in options.InstructionSet) { //添加通知数据包信息 if (instructionSet.NoticeInfos != null && instructionSet.NoticeInfos.Length > 0) { foreach (var item in instructionSet.NoticeInfos) { noticeTypeDict[item.NoticeTypeName] = item.GetNoticeType(); } } } foreach (var instructionSet in options.InstructionSet) { //添加命令数据包信息 if (instructionSet.CommandInfos != null && instructionSet.CommandInfos.Length > 0) { foreach (var item in instructionSet.CommandInfos) { var requestType = item.GetRequestType(); var responseType = item.GetResponseType(); commandRequestTypeDict[item.RequestTypeName] = requestType; commandResponseTypeDict[item.ResponseTypeName] = responseType; commandRequestTypeResponseTypeDict[requestType] = responseType; } } } }