public bool LogiGSRes(out GCLoginGameMessage msg, out bool isNeedQueryData) { msg = null; isNeedQueryData = false; bool result; if (connection == null) { LoggerManager.Instance.Info("getLoginGsResult connection null"); result = true; } else { if (connection.IsConnectionNonStart()) { LoggerManager.Instance.Debug("getLoginGsResult but no login operation"); result = false; } else { if (connection.IsConnecting()) { result = false; } else { if (connection.IsConnected()) { if (connection.LoginGameRes == null) { result = false; } else { msg = connection.LoginGameRes; LoggerManager.Instance.Debug("get connection {0} callback {1}", connection.GetHashCode(), msg.CallBackId); isNeedQueryData = msg.Protocol.NeedQueryData; if (isNeedQueryData) { connection.ClearProtocolAmount(); } result = true; } } else { result = true; } } } } return(result); }
public override void OnReceived(IConnection connection, byte[] buffer, int offset, int size) { NetworkBuffer networkBuffer = new NetworkBuffer(buffer, offset, size, true); int protocolId = networkBuffer.ReadInt32(); int callBackId = networkBuffer.ReadInt32(); Type messageType = messageInitializer.GetMessageType(protocolId); if (null == messageType) { LoggerManager.Instance.Warn("OnReceived found msg protocolId {0}-{0:X} can't getMessageType then ingored", protocolId); } else { Message message = (Message)Activator.CreateInstance(messageType); message.CallBackId = callBackId; message.DecodeBody(buffer, offset + networkBuffer.ReadOffset, networkBuffer.ReadableBytes); if (protocolId == Protocols.P_GC_GameLogin) { GCLoginGameMessage gcLoginGameMessage = (GCLoginGameMessage)message; connection.LoginGameRes = gcLoginGameMessage; LoggerManager.Instance.Info("connection {0} recv loginRes callBackId {1}", connection.GetHashCode(), gcLoginGameMessage.CallBackId); } else { connection.RecvProtocol(protocolId); IMessageHandler messageHandler = messageInitializer.GetMessageHandler(protocolId); if (messageHandler != null) { messageHandler.HandleMessage(connection, message); } else { if (!msgDelegateProcessor.HandleMessage(message, connection)) { messageHandler = messageInitializer.GetDefaultMessageHandler(); if (messageHandler != null) { messageHandler.HandleMessage(connection, message); } } } } } }
// 登录游戏服务器响应 public bool OnLoginGSRes(out GCLoginGameMessage loginRes, out bool isNeedQueryData) { PrintBusinessLog("[Serverbusiness] OnLoginGSRes"); return(protocol.LogiGSRes(out loginRes, out isNeedQueryData)); }
/// <summary> /// 处理当发送消息时, 游戏服务器断开连接的情况 /// </summary> /// <param name="message"></param> /// <param name="reSendCount"></param> /// <param name="defaultResult"></param> /// <returns></returns> public bool ProcessOnLossGSConnectWhenSendMsg(ref Message message, int reSendCount, bool defaultResult) { PLoginGS loginGS = new PLoginGS(DataModelManager.Instance.AreaInfo, null, null); loginGS.Execute(this); bool isNeedQueryData = false; bool finished = false; int counter = 0; int sleepMS = 1; // 休息毫秒数 GCLoginGameMessage loginMsg = null; while ((!finished) && sleepMS * counter < 2000) { RequestManager.Instance.Business.Update(); finished = RequestManager.Instance.Business.OnLoginGSRes(out loginMsg, out isNeedQueryData); Thread.Sleep(sleepMS); counter++; } if (finished && loginMsg != null) { UiPnlTipIndicator.CloseIndicatorIfShowing(); switch (loginMsg.ResultCode) { case Protocols.GameLoginSuccess: { if (isNeedQueryData) { ReConnectManager.Instance.HandleReQueryData(); return(true); } else { if (message != null) { SendMessage(message, reSendCount + 1); return(true); } } } break; case Protocols.GameLoginSuccessRoleNotExist: case Protocols.GameLoginFail: case Protocols.GameLoginFromOthers: case Protocols.GameLoginFailNeedActiveCode: case Protocols.GameLoginTableVersionCheckSuccessUpdate: case Protocols.TableVersionCheckSuccessUpdate: default: { ReConnectManager.Instance.HandleGSClosed(); return(true); } } } else { ReConnectManager.Instance.HandleGSClosed(); return(false); } return(defaultResult); }