Ejemplo n.º 1
0
 public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
 {
     MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), errorCode, errorInfo);
     MessageStructure sb = new MessageStructure();
     sb.WriteBuffer(head);
     response.BinaryWrite(sb.PopBuffer());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="actionGetter"></param>
 /// <param name="response"></param>
 protected void DoAction(ActionGetter actionGetter, BaseGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         OnRequested(actionGetter, response);
         ActionFactory.Request(actionGetter, response);
     }
     else
     {
         response.WriteError(actionGetter, Language.Instance.ErrorCode, Language.Instance.ServerMaintain);
     }
 }
 public override void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
 {
     var result = new ResultData()
     {
         MsgId = actionGetter.GetMsgId(),
         ActionId = actionGetter.GetActionId(),
         ErrorCode = errorCode,
         ErrorInfo = errorInfo,
         Data = null
     };
     //实现出错处理下发
     response.BinaryWrite(Encoding.UTF8.GetBytes(MathUtils.ToJson(result)));
 }
Ejemplo n.º 4
0
 public void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
 {
     //实现出错处理下发
     ResponsePack head = new ResponsePack()
     {
         MsgId = actionGetter.GetMsgId(),
         ActionId = actionGetter.GetActionId(),
         ErrorCode = errorCode,
         ErrorInfo = errorInfo,
         St = actionGetter.GetSt()
     };
     byte[] headBytes = ProtoBufUtils.Serialize(head);
     byte[] buffer = BufferUtils.AppendHeadBytes(headBytes);
     response.BinaryWrite(buffer);
 }
Ejemplo n.º 5
0
        protected override void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
        {
            try
            {
                var actionId = actionGetter.GetActionId();
                var uid = actionGetter.GetUserId();
                Console.WriteLine("Action{0} from {1}", actionId, uid);
                ActionFactory.Request(actionGetter, response, GetUser);

            }
            catch (Exception ex)
            {
                TraceLog.WriteError("{0}", ex);
            }
        }
Ejemplo n.º 6
0
        public override void WriteResponse(BaseGameResponse response)
        {
            SetResponseHead();
            byte[] headBytes = ProtoBufUtils.Serialize(_responseHead);
            byte[] contentBytes = BuildResponsePack();
            byte[] buffer = null;
            if (contentBytes == null || contentBytes.Length == 0)
            {
                buffer = BufferUtils.AppendHeadBytes(headBytes);
            }
            else
            {
                buffer = BufferUtils.MergeBytes(
                    BufferUtils.AppendHeadBytes(headBytes),
                    contentBytes
                );
            }
            //需要对字节数据加密处理,这里跳过

            response.BinaryWrite(buffer);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 输出当前协议
        /// </summary>
        protected void WriteHead(BaseGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st)
        {
            PushIntoStackObj(errorCode, 0);//int errorCode
            PushIntoStackObj(msgId, 1);//int msgid
            PushIntoStackObj(errorInfo, 2); //string info
            PushIntoStackObj(aAction, 3); //int actionId
            PushIntoStackObj(st, 4); //int St timespan
            //extent head
            if (_propertyStruct != null)
            {
                if (_propertyStruct.IsEmpty)
                {
                    PushIntoStackObj(0, 5);
                }
                else
                {
                    PushIntoStackObj(1, 5); //int property head length=1
                    PushIntoStackObj(_propertyStruct, 6);
                }
            }

            WriteActionNum(response); //total package length
            InternalWriteAction(response);
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteBool(BaseGameResponse response, Boolean aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="value"></param>
 protected static void WriteDateTime(BaseGameResponse response, DateTime value)
 {
     byte[] outputStream = BitConverter.GetBytes(value.Ticks);
     response.Write(outputStream);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(BaseGameResponse response)
 {
     foreach (object obj in arrayList)
     {
         Type type = obj.GetType();
         if (type == typeof(String))
         {
             WriteString(response, Convert.ToString(obj));
         }
         else if (type == typeof(double))
         {
             WriteDouble(response, Convert.ToDouble(obj));
         }
         else if (type == typeof(float))
         {
             WriteFloat(response, Convert.ToSingle(obj));
         }
         else if (type == typeof(Int64))
         {
             WriteLong(response, Convert.ToInt64(obj));
         }
         else if (type == typeof(Int32) || type.IsEnum)
         {
             WriteInt(response, Convert.ToInt32(obj));
         }
         else if (type == typeof(Int16))
         {
             WriteShort(response, Convert.ToInt16(obj));
         }
         else if (type == typeof(UInt64))
         {
             WriteULong(response, Convert.ToUInt64(obj));
         }
         else if (type == typeof(UInt32))
         {
             WriteUInt(response, Convert.ToUInt32(obj));
         }
         else if (type == typeof(UInt16))
         {
             WriteUShort(response, Convert.ToUInt16(obj));
         }
         else if (type == typeof(Byte))
         {
             WriteByte(response, Convert.ToByte(obj));
         }
         else if (type == typeof(bool))
         {
             WriteBool(response, Convert.ToBoolean(obj));
         }
         else if (type == typeof(DateTime))
         {
             WriteDateTime(response, Convert.ToDateTime(obj));
         }
         else if (type == typeof(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
         else if (type == typeof(byte[]))
         {
             //By Seamoon已序列化好的内容,直接写入
             var bytes = (byte[])(obj);
             WriteInt(response, bytes.Length);
             response.Write(bytes);
         }
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 protected void JsonWriteResponse(BaseGameResponse response)
 {
     if (!IsNotRespond)
     {
         var message = BuildJsonPack();
         response.Write(encoding.GetBytes(message));
     }
     WriteEnd();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(BaseGameResponse response)
 {
     foreach (object obj in arrayList)
     {
         Type type = obj.GetType();
         if (type == typeof(String))
         {
             WriteString(response, Convert.ToString(obj));
         }
         else if (type == typeof(double))
         {
             WriteDouble(response, Convert.ToDouble(obj));
         }
         else if (type == typeof(float))
         {
             WriteFloat(response, Convert.ToSingle(obj));
         }
         else if (type == typeof(Int64))
         {
             WriteLong(response, Convert.ToInt64(obj));
         }
         else if (type == typeof(Int32) || type.IsEnum)
         {
             WriteInt(response, Convert.ToInt32(obj));
         }
         else if (type == typeof(Int16))
         {
             WriteShort(response, Convert.ToInt16(obj));
         }
         else if (type == typeof(UInt64))
         {
             WriteULong(response, Convert.ToUInt64(obj));
         }
         else if (type == typeof(UInt32))
         {
             WriteUInt(response, Convert.ToUInt32(obj));
         }
         else if (type == typeof(UInt16))
         {
             WriteUShort(response, Convert.ToUInt16(obj));
         }
         else if (type == typeof(Byte))
         {
             WriteByte(response, Convert.ToByte(obj));
         }
         else if (type == typeof(bool))
         {
             WriteBool(response, Convert.ToBoolean(obj));
         }
         else if (type == typeof(DateTime))
         {
             WriteDateTime(response, Convert.ToDateTime(obj));
         }
         else if (type == typeof(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
         else if (type == typeof(byte[]))
         {
             //By Seamoon已序列化好的内容,直接写入
             var bytes = (byte[])(obj);
             WriteInt(response, bytes.Length);
             response.Write(bytes);
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 输出当前协议返回
 /// </summary>
 public void WriteAction(BaseGameResponse response)
 {
     dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 输出一个错误的Action 与 相应错误内容描述
        /// </summary>
        public void WriteErrorAction(BaseGameResponse response)
        {
            logActionResult += errorCode + "-";
            if (string.IsNullOrEmpty(errorInfo))
            {
                logActionResult += DefaultErrorInfo + "-";
            }
            else
            {
                logActionResult += errorInfo + "-";
            }
            this.iVisitEndTime = DateTime.Now;
            WatchAction();
            this.SaveActionLogToDB(LogActionStat.Fail, logActionResult);

            if (!IsNotRespond)
            {
                response.WriteError(actionGetter, errorCode, errorInfo);
            }
            //dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 public override void WriteResponse(BaseGameResponse response)
 {
     byte[] buffer = BuildResponsePack();
     response.BinaryWrite(buffer);
 }
Ejemplo n.º 16
0
 protected override void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
     Console.WriteLine("url:{0}", actionGetter.ToParamString());
     base.OnRequested(actionGetter, response);
 }
Ejemplo n.º 17
0
 protected override void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
     base.OnRequested(actionGetter, response);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteUShort(BaseGameResponse response, UInt16 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteLong(BaseGameResponse response, Int64 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Write response
 /// </summary>
 public virtual void WriteResponse(BaseGameResponse response)
 {
     BuildPacket();
     WriteAction(response);
     WriteEnd();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Write response
 /// </summary>
 public virtual void WriteResponse(BaseGameResponse response)
 {
     BuildPacket();
     WriteAction(response);
     WriteEnd();
 }
Ejemplo n.º 22
0
 /// <summary>
 /// 输出当前协议返回
 /// </summary>
 public void WriteAction(BaseGameResponse response)
 {
     if (!IsNotRespond)
     {
         dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aAction"></param>
 /// <param name="errorCode"></param>
 /// <param name="errorInfo"></param>
 /// <param name="msgId">消息初始ID</param>
 /// <param name="st"></param>
 public void WriteAction(BaseGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st = "st")
 {
     WriteHead(response, aAction, errorCode, errorInfo, msgId, st);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Write response
 /// </summary>
 public virtual void WriteResponse(BaseGameResponse response)
 {
     if (IsWebSocket)
     {
         JsonWriteResponse(response);
     }
     else
     {
         BinaryWriteResponse(response);
     }
 }
Ejemplo n.º 25
0
 protected override void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
     Console.WriteLine("Client {0} request action {1}", actionGetter.GetSessionId(), actionGetter.GetActionId());
 }
Ejemplo n.º 26
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 protected void BinaryWriteResponse(BaseGameResponse response)
 {
     if (!IsNotRespond)
     {
         BuildPacket();
     }
     WriteAction(response);
     WriteEnd();
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteString(BaseGameResponse response, string aValue)
 {
     byte[] outputStream = System.Text.Encoding.UTF8.GetBytes(aValue);
     int iLen = outputStream.Length;
     byte[] outputStreamForLen = BitConverter.GetBytes(iLen);
     response.BinaryWrite(outputStreamForLen);
     if (outputStream.Length > 0)
     {
         response.BinaryWrite(outputStream);
     }
 }
Ejemplo n.º 28
0
 protected override void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
     Console.WriteLine("Receice actionId:{0}", actionGetter.GetActionId());
     base.OnRequested(actionGetter, response);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteLong(BaseGameResponse response, Int64 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Raises the requested event.
 /// </summary>
 /// <param name="actionGetter">Http get.</param>
 /// <param name="response">Response.</param>
 protected virtual void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
 }
Ejemplo n.º 31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="value"></param>
 protected static void WriteDateTime(BaseGameResponse response, DateTime value)
 {
     long ts = (value.ToUniversalTime() - MathUtils.UnixEpochDateTime).TotalSeconds.ToLong();
     byte[] outputStream = BitConverter.GetBytes(ts);
     response.Write(outputStream);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aAction"></param>
 /// <param name="errorCode"></param>
 /// <param name="errorInfo"></param>
 /// <param name="msgId">消息初始ID</param>
 /// <param name="st"></param>
 public void WriteAction(BaseGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st = "st")
 {
     WriteHead(response, aAction, errorCode, errorInfo, msgId, st);
 }
Ejemplo n.º 33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response"></param>
        public override void WriteResponse(BaseGameResponse response)
        {
            var message = BuildResponsePack();

            response.Write(encoding.GetBytes(message));
        }
Ejemplo n.º 34
0
 /// <summary>
 /// 计算Action协议占用的字节长度
 /// </summary>
 protected void WriteActionNum(BaseGameResponse response)
 {
     int iActionNum = GetContentLen();
     WriteInt(response, iActionNum);
 }
Ejemplo n.º 35
0
        /// <summary>
        /// 计算Action协议占用的字节长度
        /// </summary>
        protected void WriteActionNum(BaseGameResponse response)
        {
            int iActionNum = GetContentLen();

            WriteInt(response, iActionNum);
        }
Ejemplo n.º 36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteBool(BaseGameResponse response, Boolean aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// 输出当前协议
 /// </summary>
 protected void WriteHead(BaseGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st)
 {
     PushIntoStackObj(errorCode, 0);
     PushIntoStackObj(msgId, 1);
     //结果String
     PushIntoStackObj(errorInfo, 2);
     PushIntoStackObj(aAction, 3);
     //St
     PushIntoStackObj(st, 4);
     WriteActionNum(response);
     InternalWriteAction(response);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteUShort(BaseGameResponse response, UInt16 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Ejemplo n.º 39
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 public override void WriteResponse(BaseGameResponse response)
 {
     byte[] buffer = BuildResponsePack();
     response.BinaryWrite(buffer);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aByte"></param>
 /// <param name="response"></param>
 protected static void WriteByte(BaseGameResponse response, byte aByte)
 {
     byte[] outputStream = new byte[1];
     outputStream[0] = aByte;
     //m_Response.OutputStream.Write(outputStream, 0, outputStream.Length);
     response.Write(outputStream);
 }
Ejemplo n.º 41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 protected void BinaryWriteResponse(BaseGameResponse response) {
     if (!isNotRespond) {
         WriteHeadProperty();
         BuildPacket();
     }
     WriteAction(response);
     WriteEnd();
 }