private void DataReceived_Handler(object sender, SocketEventArgs e) { if (e.Data.Sum() > 0) { Datagram requestDatagram = DatagramResolver.ResolveRequest(e.Data); Datagram responseDatagram = null; if (requestDatagram != null) { if (requestDatagram.Type == DatagramTypeEnum.HeartbeatRequest) { this.heartbeatCount = Interlocked.Increment(ref this.heartbeatCount); responseDatagram = this.ProcessHeartbeat(requestDatagram); } if (requestDatagram.Type == DatagramTypeEnum.LoginRequest) { this.loginCount = Interlocked.Increment(ref this.loginCount); responseDatagram = this.ProcessLogin(requestDatagram); } if (requestDatagram.Type == DatagramTypeEnum.BlacklistQueryRequest) { this.blacklistQueryCount = Interlocked.Increment(ref this.blacklistQueryCount); responseDatagram = this.ProcessBlacklistQuery(requestDatagram); } if (requestDatagram.Type == DatagramTypeEnum.BlacklistDownloadRequest) { this.blacklistDownloadCount = Interlocked.Increment(ref this.blacklistDownloadCount); responseDatagram = this.ProcessBlacklistDownload(requestDatagram); } if (requestDatagram.Type == DatagramTypeEnum.CurrencyRequest) { this.currencyCount = Interlocked.Increment(ref this.currencyCount); responseDatagram = this.ProcessCurrency(requestDatagram); } this.LocalSocketServer.BeginSend(e.Socket, responseDatagram.FullDatagram); } } }
private void DataReceived_Handler(byte[] data) { this.RoundTime = (int)DateTime.Now.Subtract(this.LastRecieveDatTime.Value).TotalMilliseconds; this.SendInterval = this.TimeOut - this.RoundTime; if (this.SendInterval < 0) { this.TimeOutCount += 1; } Datagram objDatagram = DatagramResolver.ResolveResponse(data); if (objDatagram != null) { if (objDatagram.Type == DatagramTypeEnum.HeartbeatResponse) { this.SendHeartbeatCount += 1; DataCounter.AddHeartbeat(); } if (objDatagram.Type == DatagramTypeEnum.LoginResponse) { this.SendLoginCount += 1; DataCounter.AddLogin(); } if (objDatagram.Type == DatagramTypeEnum.BlacklistQueryResponse) { BlacklistQueryResponse response = objDatagram as BlacklistQueryResponse; this.TargetDownloadBlacklist = response.BlacklistCount.ToInt16(); this.DownloadBlacklistCount = 0; DataCounter.AddBlacklistQuery(); DataCounter.AddSingleBlacklistDownload(this.TargetDownloadBlacklist); if (this.TargetDownloadBlacklist > 0) { this.IsFinishDownloadBlacklist = false; this.SendBlacklist(); } } if (objDatagram.Type == DatagramTypeEnum.BlacklistDownloadResponse) { this.DownloadBlacklistCount += 1; DataCounter.AddRealBlacklistDownload(); if (this.DownloadBlacklistCount >= this.TargetDownloadBlacklist) { this.IsFinishDownloadBlacklist = true; } else { this.SendBlacklist(); } } if (objDatagram.Type == DatagramTypeEnum.CurrencyResponse) { this.SendCurrencyCount += 1; this.SendSingleDataCurrencyCount += 1; DataCounter.AddCurrency(); if (this.SendCurrencyCount < this.TargetCurrencyCount) { if (this.SendSingleDataCurrencyCount == this.TargetSingleDayCurrencyCount) { this.SendDayCount += 1; this.SendSingleDataCurrencyCount = 0; } if (this.FixedSendSpeed && this.SendInterval > 0) { Thread.Sleep(this.SendInterval); } this.SendCurrency(); } } } }
private void DataReceived_Handler(byte[] data) { if (this.IsTimeOut) { this.TimeOutCount += 1; } this.LastRecieveDatTime = DateTime.Now; Datagram objDatagram = DatagramResolver.ResolveResponse(data); if (objDatagram != null) { if (objDatagram.Type == DatagramTypeEnum.HeartbeatResponse) { this.SendHeartbeatCount += 1; DataCounter.AddHeartbeat(); } if (objDatagram.Type == DatagramTypeEnum.LoginResponse) { this.SendLoginCount += 1; DataCounter.AddLogin(); } if (objDatagram.Type == DatagramTypeEnum.BlacklistQueryResponse) { BlacklistQueryResponse response = objDatagram as BlacklistQueryResponse; this.TargetDownloadBlacklist = response.BlacklistCount.ToInt16(); this.DownloadBlacklistCount = 0; DataCounter.AddBlacklistQuery(); DataCounter.AddSingleBlacklistDownload(this.TargetDownloadBlacklist); if (this.TargetCurrencyCount > 0) { this.IsFinishDownloadBlacklist = false; this.SendBlacklist(); } } if (objDatagram.Type == DatagramTypeEnum.BlacklistDownloadResponse) { this.DownloadBlacklistCount += 1; DataCounter.AddRealBlacklistDownload(); if (this.DownloadBlacklistCount >= this.TargetDownloadBlacklist) { this.IsFinishDownloadBlacklist = true; } else { this.SendBlacklist(); } } if (objDatagram.Type == DatagramTypeEnum.CurrencyResponse) { this.SendCurrencyCount += 1; DataCounter.AddCurrency(); if (this.SendCurrencyCount < this.TargetCurrencyCount) { Thread.Sleep(this.SendInterval); this.SendCurrency(); } } } }