Exemple #1
0
 /// <summary>
 /// 获取Action处理的输出字节流
 /// </summary>
 /// <returns></returns>
 public static byte[] GetActionResponse(int actionId, BaseUser baseUser, string parameters, out HttpGet httpGet)
 {
     string serverHost = string.Format("{0}:{1}", ActionConfig.Current.IpAddress, ActionConfig.Current.Port);
     string param = string.Format("MsgId={0}&St={1}&Sid={2}&Uid={3}&ActionID={4}{5}",
         0,
         "st",
         baseUser.GetSessionId(),
         baseUser.GetUserId(),
         actionId,
         parameters);
     httpGet = new HttpGet(param, baseUser.SocketSid, baseUser.RemoteAddress);
     BaseStruct baseStruct = FindRoute(ActionConfig.Current.TypeName, httpGet, actionId);
     SocketGameResponse response = new SocketGameResponse();
     baseStruct.UserFactory = uid => { return baseUser; };
     baseStruct.SetPush();
     baseStruct.DoInit();
     using (baseStruct.RequestLock())
     {
         if (!baseStruct.GetError() &&
             baseStruct.ReadUrlElement() &&
             baseStruct.DoAction() &&
             !baseStruct.GetError())
         {
             baseStruct.BuildPacket();
             baseStruct.WriteAction(response);
         }
         else
         {
             baseStruct.WriteErrorAction(response);
         }
     }
     return response.ReadByte();
 }
Exemple #2
0
 /// <summary>
 /// 购买商品
 /// </summary>
 /// <param name="user"></param>
 /// <param name="goodsId"></param>
 /// <param name="goodsNum"></param>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 public bool BuyGoods(BaseUser user, int goodsId, int goodsNum, out TradeErrorCode errorCode)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     errorCode = TradeErrorCode.Fail;
     var goods = _goodsList.Find(m => m.Id == goodsId);
     if (goods != null)
     {
         return _controller.TradeGoods(user, goods, goodsNum, out errorCode);
     }
     else
     {
         errorCode = TradeErrorCode.NoGodds;
     }
     return false;
 }
Exemple #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="user"></param>
 public void Notify(BaseUser user)
 {
     int gameId = GameEnvironment.ProductCode;
     int serverId = GameEnvironment.ProductServerId;
     int userId = user.GetUserId();
     string pid = user.GetPassportId();
     OrderInfo[] orderList = PayManager.getPayment(gameId, serverId, pid);
     foreach (var orderInfo in orderList)
     {
         if (DoNotify(userId, orderInfo))
         {
             PayManager.Abnormal(orderInfo.OrderNO);
             TraceLog.ReleaseWriteFatal("Payment order:{0},Pid:{1} notify success", orderInfo.OrderNO, pid);
         }
         else
         {
             TraceLog.ReleaseWriteFatal("Payment order:{0},Pid:{1} notify faild", orderInfo.OrderNO, pid);
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Dos the refresh.
 /// </summary>
 /// <param name="actionId">Action identifier.</param>
 /// <param name="gameUser">Game user.</param>
 protected void DoRefresh(int actionId, BaseUser gameUser)
 {
     if (EnablePayNotify != null)
     {
         EnablePayNotify.Notify(gameUser);
     }
     if (gameUser != null)
     {
         gameUser.RefleshOnlineDate();
     }
 }
Exemple #5
0
        /// <summary>
        /// Checks the user.
        /// </summary>
        /// <returns>The user.</returns>
        /// <param name="sessionId">Session I.</param>
        /// <param name="userId">User identifier.</param>
        /// <param name="gameUser">Game user.</param>
        protected LoginStatus CheckUser(string sessionId, int userId, out BaseUser gameUser)
        {
            gameUser = null;
            if (UserFactory != null)
            {
                gameUser = UserFactory(userId);
                if (gameUser != null)
                {
                    var session = GameSession.Get(userId);
                    if (session != null)
                    {
                        return session.SessionId == sessionId ? LoginStatus.Success : LoginStatus.Logined;
                    }

                    //todo session
                    session = GameSession.Get(sessionId);
                    TraceLog.ReleaseWriteDebug("User no login, Sid:{0},Uid:{1},session info:{2}", sessionId, userId,
                        session == null ? "is empty" :
                        string.Format("bind uid:{0}", session.UserId)
                        );
                }
            }
            return LoginStatus.NoLogin;
        }
 protected override bool SendGoods(BaseUser user, object items)
 {
     //交易成功,向玩家背包放入物品
 }
 protected override bool PayAmount(BaseUser user, int tradeType, double payAmount)
 {
     //扣除玩家代币
 }
 protected override bool HasTraded(BaseUser user, GoodsData goods, int goodsNum, out double amount, out TradeErrorCode errorCode)
 {
     //检查是否可交易
 }
Exemple #9
0
 /// <summary>
 /// Checks the user.
 /// </summary>
 /// <returns>The user.</returns>
 /// <param name="sessionID">Session I.</param>
 /// <param name="userId">User identifier.</param>
 /// <param name="gameUser">Game user.</param>
 protected LoginStatus CheckUser(string sessionID, int userId, out BaseUser gameUser)
 {
     gameUser = null;
     if (UserFactory != null)
     {
         gameUser = UserFactory(userId);
         if (gameUser != null)
         {
             string currSid = gameUser.GetSessionId();
             if (!string.IsNullOrEmpty(currSid))
             {
                 return currSid == sessionID ? LoginStatus.Success : LoginStatus.Logined;
             }
         }
     }
     return LoginStatus.NoLogin;
 }
Exemple #10
0
 /// <summary>
 /// Checks the user.
 /// </summary>
 /// <returns>The user.</returns>
 /// <param name="sessionID">Session I.</param>
 /// <param name="userId">User identifier.</param>
 /// <param name="gameUser">Game user.</param>
 protected LoginStatus CheckUser(string sessionID, int userId, out BaseUser gameUser)
 {
     gameUser = null;
     if (UserFactory != null)
     {
         gameUser = UserFactory(userId);
         if (gameUser != null)
         {
             var session = GameSession.Get(userId);
             if (session != null)
             {
                 return session.SessionId == sessionID ? LoginStatus.Success : LoginStatus.Logined;
             }
         }
     }
     return LoginStatus.NoLogin;
 }
Exemple #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="roleUser"></param>
 public SessionUser(BaseUser roleUser)
     : this()
 {
     PassportId = roleUser.GetPassportId();
     UserId = roleUser.GetUserId();
 }
		/// <summary>
		/// Trades the goods.
		/// </summary>
		/// <returns><c>true</c>, if goods was traded, <c>false</c> otherwise.</returns>
		/// <param name="user">User.</param>
		/// <param name="goods">Goods.</param>
		/// <param name="goodsNum">Goods number.</param>
		/// <param name="errorCode">Error code.</param>
        public bool TradeGoods(BaseUser user, GoodsData goods, int goodsNum, out TradeErrorCode errorCode)
        {
            bool result = false;
            if (_tradeStrategy.TryEnterTraded(goods))
            {
                try
                {
                    double payAmount;
                    if (HasTraded(user, goods, goodsNum, out payAmount, out errorCode))
                    {
                        var items = ProduceGoods(goods, goodsNum);
                        if (SendGoods(user, items) && PayAmount(user, goods.TradeType, payAmount))
                        {
                            TradeSuccess(user, goods, goodsNum, payAmount, items);
                            errorCode = TradeErrorCode.Sucess;
                            result = true;
                        }
                        else
                        {
                            errorCode = TradeErrorCode.Fail;
                        }
                    }
                }
                finally
                {
                    _tradeStrategy.ExitTraded();
                }
            }
            else
            {
                errorCode = TradeErrorCode.TradeTimeout;
            }
            return result;
        }
 /// <summary>
 /// 派送商品
 /// </summary>
 /// <param name="user"></param>
 /// <param name="items"></param>
 /// <returns></returns>
 protected abstract bool SendGoods(BaseUser user, object items);
 /// <summary>
 /// 支付代币
 /// </summary>
 /// <param name="user"></param>
 /// <param name="tradeType"></param>
 /// <param name="payAmount"></param>
 /// <returns></returns>
 protected abstract bool PayAmount(BaseUser user, int tradeType, double payAmount);
 /// <summary>
 /// 检查是否可交易
 /// </summary>
 /// <param name="user"></param>
 /// <param name="goods"></param>
 /// <param name="goodsNum"></param>
 /// <param name="amount"></param>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 protected abstract bool HasTraded(BaseUser user, GoodsData goods, int goodsNum, out double amount, out TradeErrorCode errorCode);
        /// <summary>
        /// 交易成功
        /// </summary>
        /// <param name="user"></param>
        /// <param name="goods"></param>
        /// <param name="goodsNum"></param>
        /// <param name="payAmount"></param>
        /// <param name="items"></param>
        protected virtual void TradeSuccess(BaseUser user, GoodsData goods, int goodsNum, double payAmount, object items)
        {

        }