public void ThenGameResponseIsPublishedWithMessageIDAndSessionID(string sessionID, string messageID, string cardID, int packVersion, int seed, string cardtoAdd, float probability)
            {
                GameDataGatewaySpy gameDataGatewaySpy = new GameDataGatewaySpy();
                PublishEndPointSpy publishEndPointSpy = new PublishEndPointSpy();

                Tuple <string, float>[] cardsToAdd      = { new Tuple <string, float>(cardtoAdd, probability) };
                SaveNewGameData         saveNewGameData =
                    new SaveNewGameData(gameDataGatewaySpy,
                                        publishEndPointSpy);

                saveNewGameData.Execute(
                    sessionID,
                    messageID,
                    new GameDataDummy
                {
                    CurrentCardID = cardID,
                    Seed          = seed,
                    PackVersion   = packVersion,
                    CardsToAdd    = cardsToAdd
                }
                    );
                Assert.True(publishEndPointSpy.MessageObject is IGameResponse);
                IGameResponse gameResponse = (IGameResponse)publishEndPointSpy.MessageObject;

                Assert.True(gameResponse.SessionID == sessionID);
                Assert.True(gameResponse.MessageID == messageID);
            }
Example #2
0
        /// <summary>
        /// 请求脚本处理
        /// </summary>
        /// <param name="httpGet">请求参数对象</param>
        /// <param name="response">字节输出处理</param>
        /// <param name="userFactory">创建user对象工厂,可为Null</param>
        public static void RequestScript(HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
        {
            int    actionID  = httpGet.ActionId;
            string errorInfo = "";

            try
            {
                bool isRl = BaseStruct.CheckRunloader(httpGet);
                if (isRl || httpGet.CheckSign())
                {
                    BaseStruct baseStruct = FindScriptRoute(httpGet, actionID);
                    if (baseStruct != null)
                    {
                        Process(baseStruct, httpGet, response, userFactory);
                        return;
                    }
                }
                else
                {
                    errorInfo = "Sign Error";
                    TraceLog.WriteError("Action request error:{2},rl:{0},param:{1}", isRl, httpGet.ParamString, errorInfo);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Action request error:{0}\r\nparam:{1}", ex, httpGet.ParamString);
            }
            RequestError(response, actionID, errorInfo);
        }
Example #3
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aByte"></param>
 /// <param name="m_Response"></param>
 protected static void WriteByte(IGameResponse m_Response, byte aByte)
 {
     byte[] outputStream = new byte[1];
     outputStream[0] = aByte;
     //m_Response.OutputStream.Write(outputStream, 0, outputStream.Length);
     m_Response.Write(outputStream);
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="response"></param>
        /// <param name="userFactory"></param>
        /// <param name="httpGet"></param>
        public static void Request(string typeName, HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
        {
            int    actionID  = 0;
            string errorInfo = "";

            try
            {
                bool isRL = BaseStruct.CheckRunloader(httpGet);
                if (isRL || httpGet.CheckSign())
                {
                    if (httpGet.GetInt("ActionID", ref actionID))
                    {
                        BaseStruct action = FindRoute(typeName, httpGet, actionID);
                        Process(action, httpGet, response, userFactory);
                        if (action != null)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    errorInfo = "签名验证失败";
                    TraceLog.WriteError("Action request error:{2},rl:{0},param:{1}", isRL, httpGet.ParamString, errorInfo);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Action request error:{0}\r\nparam:{1}", ex, httpGet.ParamString);
            }
            RequestError(response, actionID, 10000, errorInfo);
        }
Example #5
0
 /// <summary>
 /// 输出当前协议返回
 /// </summary>
 public void WriteAction(IGameResponse response)
 {
     dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
     this.iVisitEndTime = DateTime.Now;
     WatchAction();
     this.SaveActionLogToDB(LogActionStat.Sucess, this.logActionResult);
 }
Example #6
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(IGameResponse response)
 {
     foreach (object obj in arrayList)
     {
         if (obj.GetType() == typeof(String))
         {
             WriteString(response, Convert.ToString(obj));
         }
         else if (obj.GetType() == typeof(Int32))
         {
             WriteDWord(response, Convert.ToInt32(obj));
         }
         else if (obj.GetType() == typeof(Int16))
         {
             WriteWord(response, Convert.ToInt16(obj));
         }
         else if (obj.GetType() == typeof(Byte))
         {
             WriteByte(response, Convert.ToByte(obj));
         }
         else if (obj.GetType() == typeof(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
     }
 }
Example #7
0
        /// <summary>
        /// 请求处理
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="response"></param>
        /// <param name="userFactory"></param>
        /// <param name="httpGet"></param>
        public static void Request(string typeName, HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
        {
            int    actionID  = httpGet.ActionId;
            string tempName  = string.Format(typeName, httpGet.ActionId);
            string errorInfo = "";

            try
            {
                bool isRL = BaseStruct.CheckRunloader(httpGet);
                if (isRL || httpGet.CheckSign())
                {
                    BaseStruct action = FindRoute(typeName, httpGet, actionID);
                    Process(action, httpGet, response, userFactory);
                    if (action != null)
                    {
                        return;
                    }
                }
                else
                {
                    errorInfo = "Sign Error";
                    TraceLog.WriteError("Action request {3} error:{2},rl:{0},param:{1}", isRL, httpGet.ParamString, errorInfo, tempName);
                }
            }
            catch (Exception ex)
            {
                errorInfo = string.Format("Action request {0} error:{1}", tempName, ex);
                TraceLog.WriteError("Action request {0} error:{1}\r\nparam:{2}", tempName, ex, httpGet.ParamString);
            }
            RequestError(response, actionID, errorInfo);
        }
Example #8
0
        /// <summary>
        /// 出错处理
        /// </summary>
        /// <param name="response"></param>
        /// <param name="actionID"></param>
        /// <param name="errorCode"></param>
        /// <param name="errorInfo"></param>
        public static void RequestError(IGameResponse response, int actionID, int errorCode, string errorInfo)
        {
            MessageHead      head = new MessageHead(actionID, errorCode, errorInfo);
            MessageStructure sb   = new MessageStructure();

            sb.WriteBuffer(head);
            response.BinaryWrite(sb.PopBuffer());
        }
Example #9
0
 /// <summary>
 /// Raises the requested event.
 /// </summary>
 /// <param name="httpGet">Http get.</param>
 /// <param name="response">Response.</param>
 protected virtual void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         ActionFactory.Request(httpGet, response, GetUser);
     }
     else
     {
         ActionFactory.RequestError(response, httpGet.ActionId, Language.Instance.ServerMaintain);
     }
 }
Example #10
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     try
     {
         ActionFactory.Request(httpGet, response, GetUser);
     }
     catch (Exception ex)
     {
         Console.WriteLine("OnRequested error:{0}", ex.Message);
     }
 }
Example #11
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     try
     {
         ActionFactory.Request(httpGet, response, GetUser);
     }
     catch (Exception ex)
     {
         Console.WriteLine("OnRequested error:{0}", ex.Message);
     }
 }
Example #12
0
 /// <summary>
 /// 输出当前协议
 /// </summary>
 protected void WriteHead(IGameResponse 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);
 }
Example #13
0
        /// <summary>
        /// 写入字节流
        /// </summary>
        /// <param name="aValue"></param>
        /// <param name="response"></param>
        protected static void WriteString(IGameResponse 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);
            }
        }
Example #14
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(IGameResponse 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)
         {
             WriteDWord(response, Convert.ToInt32(obj));
         }
         else if (type == typeof(Int16))
         {
             WriteWord(response, Convert.ToInt16(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(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
         else if (type == typeof(byte[]))
         {
             //By Seamoon已序列化好的内容,直接写入
             var bytes = (byte[])(obj);
             WriteDWord(response, bytes.Length);
             response.Write(bytes);
         }
     }
 }
Example #15
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     try
     {
         //var actionId = httpGet.GetString("ActionID").ToInt();
         //var uid = httpGet.GetString("uid");
         //Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid);
         ActionFactory.Request(httpGet, response, userId => new GameDataCacheSet <GameUser>().FindKey(userId.ToNotNullString()));
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("{0}", ex);
     }
 }
Example #16
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     try
     {
         var actionId = httpGet.ActionId;
         var uid      = httpGet.GetString("uid");
         Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid);
         ActionFactory.Request(httpGet, response, GetUser);
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("{0}", ex);
     }
 }
Example #17
0
        protected override void OnRequested(HttpGet httpGet, IGameResponse response)
        {
            try
            {
                var actionId = httpGet.ActionId;
                var uid = httpGet.GetString("uid");
                Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid);
                ActionFactory.Request(httpGet, response, userId => new GameDataCacheSet<GameUser>().FindKey(userId.ToNotNullString()));

            }
            catch (Exception ex)
            {
                TraceLog.WriteError("{0}", ex);
            }
        }
Example #18
0
        protected override void OnRequested(HttpGet httpGet, IGameResponse response)
        {
            try
            {
                var actionId = httpGet.ActionId;
                var uid = httpGet.GetString("uid");
                Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid);
                ActionFactory.Request(httpGet, response, GetUser);

            }
            catch (Exception ex)
            {
                TraceLog.WriteError("{0}", ex);
            }
        }
        public override IGameResponse ProcessRequest <T>(IGameRequest request)
        {
            IGameResponse response = null;

            if (request is GetPlacementRequest)
            {
                GetPlacementRequest gpr = (GetPlacementRequest)request;
                response = GetPlacementRequest(gpr);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(response);
        }
Example #20
0
 /// <summary>
 /// 输出一个错误的Action 与 相应错误内容描述
 /// </summary>
 public void WriteErrorAction(IGameResponse response)
 {
     logActionResult += errorCode.ToString() + "-";
     if (string.IsNullOrEmpty(errorInfo))
     {
         logActionResult += DefaultErrorInfo + "-";
     }
     else
     {
         logActionResult += errorInfo + "-";
     }
     this.iVisitEndTime = DateTime.Now;
     WatchAction();
     this.SaveActionLogToDB(LogActionStat.Fail, logActionResult);
     dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
 }
Example #21
0
        protected override void OnRequested(HttpGet httpGet, IGameResponse response)
        {
            try
            {
                //int actionId = 0;
                //if (httpGet.GetInt("actionId", ref actionId))
                //{
                //    Console.WriteLine("request actionId:{0}", actionId);

                //}
                ActionFactory.Request(httpGet, response, userId => new GameDataCacheSet<GameUser>().FindKey(userId.ToNotNullString()));
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("d={0},{1}", httpGet.ParamString, ex.ToString());
            }
        }
Example #22
0
        protected override void OnRequested(HttpGet httpGet, IGameResponse response)
        {
            try
            {
                //int actionId = 0;
                //if (httpGet.GetInt("actionId", ref actionId))
                //{
                //    Console.WriteLine("request actionId:{0}", actionId);

                //}
                ActionFactory.Request(httpGet, response, userId => new GameDataCacheSet <GameUser>().FindKey(userId.ToNotNullString()));
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("d={0},{1}", httpGet.ParamString, ex.ToString());
            }
        }
Example #23
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     try
     {
         GuestUser user = null;
         if (_sessions.ContainsKey(httpGet.RemoteAddress))
         {
             user = _sessions[httpGet.RemoteAddress];
         }
         ActionFactory.Request(httpGet, response, GetUser);
         if (user != null)
         {
             httpGet.LoginSuccessCallback(user.UserId);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("OnRequested error:{0}", ex.Message);
     }
 }
Example #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="baseStruct"></param>
 /// <param name="httpGet"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 public static void Process(BaseStruct baseStruct, HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
 {
     baseStruct.UserFactory = userFactory;
     baseStruct.DoInit();
     using (baseStruct.RequestLock())
     {
         if (!baseStruct.GetError() &&
             baseStruct.ReadUrlElement() &&
             baseStruct.DoAction() &&
             !baseStruct.GetError())
         {
             baseStruct.BuildPacket();
             baseStruct.WriteAction(response);
         }
         else
         {
             baseStruct.WriteErrorAction(response);
         }
     }
 }
            public void ThenGameResponseIsPublishedWithCorrectGameData(string sessionID, string messageID, string cardID, int packVersion, int seed, string cardtoAdd, float probability, string statKey, int statValue)
            {
                GameDataGatewaySpy gameDataGatewaySpy = new GameDataGatewaySpy();
                PublishEndPointSpy publishEndPointSpy = new PublishEndPointSpy();

                Tuple <string, float>[] cardsToAdd      = { new Tuple <string, float>(cardtoAdd, probability) };
                SaveNewGameData         saveNewGameData =
                    new SaveNewGameData(gameDataGatewaySpy,
                                        publishEndPointSpy);

                saveNewGameData.Execute(
                    sessionID,
                    messageID,
                    new GameDataDummy
                {
                    CurrentCardID = cardID,
                    Seed          = seed,
                    PackVersion   = packVersion,
                    CardsToAdd    = cardsToAdd,
                    CurrentStats  = new Dictionary <string, int> {
                        { statKey, statValue }
                    }
                }
                    );
                Assert.True(publishEndPointSpy.MessageObject is IGameResponse);
                IGameResponse gameResponse = (IGameResponse)publishEndPointSpy.MessageObject;

                Assert.True(gameResponse.Seed == seed);
                Assert.True(gameResponse.PackVersion == packVersion);
                Assert.True(gameResponse.CurrentCardID == cardID);
                Assert.True(gameResponse.CardsToAdd[0].Item1 == cardtoAdd);
                Assert.True(gameResponse.CardsToAdd[0].Item2 == probability);
                Assert.True(gameResponse.Seed == seed);
                Assert.True(gameResponse.CurrentStats.ContainsKey(statKey));
                Assert.True(gameResponse.CurrentStats[statKey] == statValue);
            }
Example #26
0
        /// <summary>
        /// 计算Action协议占用的字节长度
        /// </summary>
        protected void WriteActionNum(IGameResponse response)
        {
            int iActionNum = GetContentLen();

            WriteDWord(response, iActionNum);
        }
Example #27
0
 /// <summary>
 /// 请求脚本处理
 /// </summary>
 /// <param name="httpGet">请求参数对象</param>
 /// <param name="response">字节输出处理</param>
 /// <param name="userFactory">创建user对象工厂,可为Null</param>
 public static void RequestScript(HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory)
 {
     int actionID = httpGet.GetInt("actionId");
     string errorInfo = "";
     try
     {
         bool isRl = BaseStruct.CheckRunloader(httpGet);
         if (isRl || httpGet.CheckSign())
         {
             ScriptRoute scriptRoute = new ScriptRoute(actionID);
             RouteItem routeItem;
             var pythonManager = PythonScriptManager.Current;
             if (pythonManager.TryGetAction(actionID, out routeItem))
             {
                 if (scriptRoute.TryLoadAction(routeItem.ScriptPath))
                 {
                     var baseStruct = new ScriptAction((short)actionID, httpGet, scriptRoute, routeItem.IgnoreAuthorize);
                     Process(baseStruct, httpGet, response, userFactory);
                     return;
                 }
             }
         }
         else
         {
             errorInfo = "签名验证失败";
             TraceLog.WriteError("Action request error:{2},rl:{0},param:{1}", isRl, httpGet.ParamString, errorInfo);
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Action request error:{0}\r\nparam:{1}", ex, httpGet.ParamString);
     }
     RequestError(response, actionID, errorInfo);
 }
Example #28
0
 /// <summary>
 /// Raises the requested event.
 /// </summary>
 /// <param name="httpGet">Http get.</param>
 /// <param name="response">Response.</param>
 protected virtual void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         //todo trace
     #if DEBUG
         ActionFactory.RequestError(response, httpGet.ActionId, 0, "");
     #else
         ActionFactory.Request(httpGet, response, GetUser);
     #endif
     }
     else
     {
         ActionFactory.RequestError(response, httpGet.ActionId, Language.Instance.ServerMaintain);
     }
 }
Example #29
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(IGameResponse response)
 {
     foreach (object obj in arrayList)
     {
         if (obj.GetType() == typeof(String))
         {
             WriteString(response, Convert.ToString(obj));
         }
         else if (obj.GetType() == typeof(Int32))
         {
             WriteDWord(response, Convert.ToInt32(obj));
         }
         else if (obj.GetType() == typeof(Int16))
         {
             WriteWord(response, Convert.ToInt16(obj));
         }
         else if (obj.GetType() == typeof(Byte))
         {
             WriteByte(response, Convert.ToByte(obj));
         }
         else if (obj.GetType() == typeof(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
     }
 }
Example #30
0
 /// <summary>
 /// 出错处理
 /// </summary>
 /// <param name="response"></param>
 /// <param name="actionID"></param>
 /// <param name="errorInfo"></param>
 public static void RequestError(IGameResponse response, int actionID, string errorInfo)
 {
     RequestError(response, actionID, ErrorCode, errorInfo);
 }
Example #31
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteBool(IGameResponse response, Boolean aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #32
0
 /// <summary>
 /// 输出一个错误的Action 与 相应错误内容描述
 /// </summary>
 public void WriteErrorAction(IGameResponse response)
 {
     logActionResult += errorCode.ToString() + "-";
     if (string.IsNullOrEmpty(errorInfo))
     {
         logActionResult += DefaultErrorInfo + "-";
     }
     else
     {
         logActionResult += errorInfo + "-";
     }
     this.iVisitEndTime = DateTime.Now;
     WatchAction();
     this.SaveActionLogToDB(LogActionStat.Fail, logActionResult);
     dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
 }
Example #33
0
 /// <summary>
 /// 请求脚本处理
 /// </summary>
 /// <param name="httpGet">请求参数对象</param>
 /// <param name="response">字节输出处理</param>
 /// <param name="userFactory">创建user对象工厂,可为Null</param>
 public static void RequestScript(HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory)
 {
     int actionID = httpGet.ActionId;
     string errorInfo = "";
     try
     {
         bool isRl = BaseStruct.CheckRunloader(httpGet);
         if (isRl || httpGet.CheckSign())
         {
             BaseStruct baseStruct = FindScriptRoute(httpGet, actionID);
             if (baseStruct != null)
             {
                 Process(baseStruct, httpGet, response, userFactory);
                 return;
             }
         }
         else
         {
             errorInfo = "签名验证失败";
             TraceLog.WriteError("Action request error:{2},rl:{0},param:{1}", isRl, httpGet.ParamString, errorInfo);
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Action request error:{0}\r\nparam:{1}", ex, httpGet.ParamString);
     }
     RequestError(response, actionID, errorInfo);
 }
Example #34
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="baseStruct"></param>
 /// <param name="httpGet"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 public static void Process(BaseStruct baseStruct, HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory)
 {
     baseStruct.UserFactory = userFactory;
     baseStruct.DoInit();
     using (ILocking locking = baseStruct.RequestLock())
     {
         if (locking.IsLocked)
         {
             if (!baseStruct.GetError() &&
                 baseStruct.ReadUrlElement() &&
                 baseStruct.DoAction() &&
                 !baseStruct.GetError())
             {
                 baseStruct.BuildPacket();
                 baseStruct.WriteAction(response);
             }
             else
             {
                 baseStruct.WriteErrorAction(response);
             }
         }
     }
 }
Example #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteFloat(IGameResponse response, float aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #36
0
 /// <summary>
 /// 内部输出Action的值
 /// </summary>
 /// <returns>无</returns>
 protected void InternalWriteAction(IGameResponse 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)
         {
             WriteDWord(response, Convert.ToInt32(obj));
         }
         else if (type == typeof(Int16))
         {
             WriteWord(response, Convert.ToInt16(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(DataStruct))
         {
             DataStruct ds = ((DataStruct)obj);
             ds.WriteActionNum(response);
             ds.InternalWriteAction(response);
         }
         else if (type == typeof(byte[]))
         {
             //By Seamoon已序列化好的内容,直接写入
             var bytes = (byte[])(obj);
             WriteDWord(response, bytes.Length);
             response.Write(bytes);
         }
     }
 }
Example #37
0
 /// <summary>
 /// 请求处理
 /// </summary>
 /// <param name="httpGet"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 public static void Request(HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
 {
     Request(GameEnvironment.Setting.ActionTypeName, httpGet, response, userFactory);
 }
Example #38
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     Console.WriteLine("Request data ActionId:{0},ip:{1}", httpGet.ActionId, httpGet.RemoteAddress);
     ActionFactory.Request(httpGet, response, null);
 }
Example #39
0
 protected abstract void OnRequested(HttpGet httpGet, IGameResponse response);
Example #40
0
 /// <summary>
 /// 请求处理
 /// </summary>
 /// <param name="httpGet"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 public static void Request(HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory)
 {
     Request(ActionConfig.Current.TypeName, httpGet, response, userFactory);
 }
Example #41
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(IGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st = "st")
 {
     WriteHead(response, aAction, errorCode, errorInfo, msgId, st);
 }
Example #42
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteFloat(IGameResponse response, float aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #43
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteString(IGameResponse 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);
     }
 }
Example #44
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteWord(IGameResponse response, Int16 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #45
0
 /// <summary>
 /// 输出当前协议返回
 /// </summary>
 public void WriteAction(IGameResponse response)
 {
     dataStruct.WriteAction(response, actionId, errorCode, errorInfo, MsgId, St);
     this.iVisitEndTime = DateTime.Now;
     WatchAction();
     this.SaveActionLogToDB(LogActionStat.Sucess, this.logActionResult);
 }
Example #46
0
 /// <summary>
 /// 出错处理
 /// </summary>
 /// <param name="response"></param>
 /// <param name="actionID"></param>
 /// <param name="errorCode"></param>
 /// <param name="errorInfo"></param>
 public static void RequestError(IGameResponse response, int actionID, int errorCode, string errorInfo)
 {
     MessageHead head = new MessageHead(actionID, errorCode, errorInfo);
     MessageStructure sb = new MessageStructure();
     sb.WriteBuffer(head);
     response.BinaryWrite(sb.ReadBuffer());
 }
Example #47
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     Console.WriteLine("Request data:{0}", httpGet.ParamString);
 }
Example #48
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aByte"></param>
 /// <param name="m_Response"></param>
 protected static void WriteByte(IGameResponse m_Response, byte aByte)
 {
     byte[] outputStream = new byte[1];
     outputStream[0] = aByte;
     //m_Response.OutputStream.Write(outputStream, 0, outputStream.Length);
     m_Response.Write(outputStream);
 }
Example #49
0
 /// <summary>
 /// 输出当前协议
 /// </summary>
 protected void WriteHead(IGameResponse 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);
 }
Example #50
0
 /// <summary>
 /// 写入字节流
 /// </summary>
 /// <param name="aValue"></param>
 /// <param name="response"></param>
 protected static void WriteWord(IGameResponse response, Int16 aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #51
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="httpGet"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 public static void Request(HttpGet httpGet, IGameResponse response, Func <int, BaseUser> userFactory)
 {
     Request(ActionConfig.Current.TypeName, httpGet, response, userFactory);
 }
Example #52
0
 /// <summary>
 /// 计算Action协议占用的字节长度
 /// </summary>
 protected void WriteActionNum(IGameResponse response)
 {
     int iActionNum = GetContentLen();
     WriteDWord(response, iActionNum);
 }
Example #53
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
 }
Example #54
0
 protected override void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     Console.WriteLine("Request data:{0}", httpGet.ParamString);
 }
Example #55
0
 /// <summary>
 /// 出错处理
 /// </summary>
 /// <param name="response"></param>
 /// <param name="actionID"></param>
 /// <param name="errorInfo"></param>
 public static void RequestError(IGameResponse response, int actionID, string errorInfo)
 {
     RequestError(response, actionID, ErrorCode, errorInfo);
 }
Example #56
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(IGameResponse response, int aAction, int errorCode, string errorInfo, int msgId, string st = "st")
 {
     WriteHead(response, aAction, errorCode, errorInfo, msgId, st);
 }
Example #57
0
 /// <summary>
 /// 请求处理
 /// </summary>
 /// <param name="typeName"></param>
 /// <param name="response"></param>
 /// <param name="userFactory"></param>
 /// <param name="httpGet"></param>
 public static void Request(string typeName, HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory)
 {
     string tempName = string.Format(typeName, httpGet.ActionId);
     int actionID = 0;
     string errorInfo = "";
     try
     {
         bool isRL = BaseStruct.CheckRunloader(httpGet);
         if (isRL || httpGet.CheckSign())
         {
             if (httpGet.GetInt("ActionID", ref actionID))
             {
                 BaseStruct action = FindRoute(typeName, httpGet, actionID);
                 Process(action, httpGet, response, userFactory);
                 if (action != null)
                 {
                     return;
                 }
             }
         }
         else
         {
             errorInfo = "签名验证失败";
             TraceLog.WriteError("Action request {3} error:{2},rl:{0},param:{1}", isRL, httpGet.ParamString, errorInfo, tempName);
         }
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Action request {0} error:{1}\r\nparam:{2}", tempName, ex, httpGet.ParamString);
     }
     RequestError(response, actionID, errorInfo);
 }
Example #58
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="aValue"></param>
 protected static void WriteDouble(IGameResponse response, double aValue)
 {
     byte[] outputStream = BitConverter.GetBytes(aValue);
     response.Write(outputStream);
 }
Example #59
0
 protected abstract void OnRequested(HttpGet httpGet, IGameResponse response);