void OnResponse(ResponseFormat res) { SocketRequestEntry req = this.requests.Find(r => r.RequestId == res.id); if (req != null) { this.requests.Remove(req); req.Response = res; IResponse response = this.responseList.Find(x => x.GetRid() == res.id); if (response == null) { Logger.Error("[IngameClient.OnResponse] response is not found"); return; } if (this.responseList.Remove(response) == false) { Logger.Error("[IngameClient.OnResponse] remove failed."); } response.ExcuteCallback(); } }
public void Send <T>(RequestFormat request, Response <T> response) where T : class { if (this.state != SocketState.Connected) { return; } SocketRequestEntry ingameRequest = new SocketRequestEntry(request, typeof(T)); ingameRequest.RequestTime = DateTime.UtcNow; requests.Add(ingameRequest); EnqueueRequestId(lastRequestId); byte[] bytes = BsonSerializer.SerializeToByte(request); Send(bytes); if (Logger.IsMutePacket(request.method) == false) { Logger.Debug(string.Format("<color=#86E57F>[Send]</color> method = {0} rid = {1}", request.method, request.id)); } this.responseList.Add(new ResponseEntry <T>() { request = ingameRequest, responseCallback = response }); }