Ejemplo n.º 1
0
 private void OnSocketClosing(object sender, EndPoint gamePoint)
 {
     if (sender is byte[])
     {
         PacketMessage packet = PacketMessage.Parse(sender as byte[]);
         PacketMessage error  = PacketMessage.CreateError(packet.Head, MessageError.SystemError, LanguageHelper.GetLang().ServerBusy);
         OnSendToClient(packet.Head.Address, error.ToByte());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送数据到游戏服
        /// </summary>
        /// <param name="clientAddress">客户端的地址</param>
        /// <param name="data"></param>
        public override void Send(string clientAddress, byte[] data)
        {
            PacketHead head = null;

            try
            {
                PacketMessage packet = PacketMessage.Parse(data);
                head = packet.Head;
                switch (head.MsgType)
                {
                case PacketMsgType.Request:
                    var session = GameSessionManager.GetSession(head.GameId, head.ServerId);
                    if (session != null)
                    {
                        string gameAddress = session.GameAddress;
                        OnSendToGame(gameAddress, data);
                    }
                    else
                    {
                        var error = PacketMessage.CreateError(head, MessageError.NotFound, LanguageHelper.GetLang().ServerMaintain);
                        OnSendToClient(clientAddress, error.ToByte());
                        TraceLog.WriteError("Can not find the game:{0} server:{1}", head.GameId, head.ServerId);
                    }
                    break;

                default:
                    throw new Exception(string.Format("The message type:{0} is not supported.", head.MsgType));
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Send game to {0} error:{1}", clientAddress, ex);
                var error = PacketMessage.CreateError(head, MessageError.SystemError, LanguageHelper.GetLang().ServerBusy);
                OnSendToClient(clientAddress, error.ToByte());
            }
        }