Beispiel #1
0
        /// <summary>
        /// 处理接收的分货请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public override CompactResponse Process(Socket client, CompactRequest request)
        {
            try
            {
                CompactResponse response = new CompactResponse();
                response.Ret = 4;
                if (request.Queries == null || request.Queries.Count < 10)
                {
                    LogWrapper.Warn("ShipErr:" + request.Url);
                    response.Msg = "404";
                    return response;
                }

                Order order = Order.CreateShipment(request.Queries);
                order.Url = request.Url;
                response.Msg = order.token;

                //验证签名
                if (ServerManager.CheckSig)
                {
                    int index = request.Url.IndexOf('?');
                    if (index > 0)
                    {
                        string path = request.Url.Substring(0, index);
                        string sig = order.GetSig(path);
                        if (sig != order.sig)
                        {
                            response.Msg = "请求参数错误(sig)";
                            return response;
                        }
                    }
                    else
                    {
                        response.Msg = "404";
                        return response;
                    }
                }

                //根据Token取角色ID
                int pid = OrderAccess.Instance.Replenish(order, 11);
                PlayerBusiness player = PlayersProxy.FindPlayerByID(pid);
                if (player == null)
                {
                    response.Ret = 3;
                    return response;
                }

                int totalCoin = 0;
                //取商品
                try
                {
                    ShipInfo[] shipInfos = order.GetShipInfos();
                    foreach (ShipInfo shipInfo in shipInfos)
                    {
                        GameConfig gs = GameConfigAccess.Instance.FindOneById(shipInfo.GoodID);
                        if (gs == null)
                        {
                            response.Ret = 2;
                            return response;
                        }
                        int num = shipInfo.Num;
                        int coin = gs.UI.GetIntOrDefault("Coin");
                        //int price = gs.UI.GetIntOrDefault("Price");
                        //if (price != shipInfo.Price)
                        //{
                        //    resp.Ret = 3;
                        //    return resp;
                        //}
                        if (coin > 0)
                        {
                            totalCoin += coin * num;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    response.Msg = ex.Message;
                    LogWrapper.Error("充值:" + request.Url, ex);
                    return response;
                }

                order.Coin = totalCoin;
                if (ResponseCompleted(client, order, player))
                {
                    return null;
                }
                response.Ret = 2;
                return response;
            }
            catch (System.Exception ex)
            {
                LogWrapper.Error(ex);
                return null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 处理接收的发货请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public override CompactResponse Process(Socket client, CompactRequest request)
        {
            try
            {
                CompactResponse response = new CompactResponse();
                response.Ret = 4;

                string auth, sign;

                if (request.Queries == null
                    || request.Queries.Count < 2
                    || (!request.Queries.TryGetValue("auth", out auth))
                    || (!request.Queries.TryGetValue("sign", out sign))
                    )
                {
                    LogWrapper.Warn("ShipErr:" + request.Url);
                    response.Msg = "404";
                    return response;
                }

                //检查签名.
                string test = MD5Helper.MD5Encrypt(auth + ConfigLoader.Config.RechargeKey);
                if (test != sign.ToUpper())
                {
                    return Send(client, OrderResult.SignError);
                }

                Order order = CreateOrder(auth, sign);
                //检查时间(7天)
                OrderResult r = OrderTypeManager.CheckOrder(order, 3600 * 24 * 7);
                if (r != OrderResult.Success)
                {
                    return Send(client, r);
                }

                //根据Token取角色ID
                int pid = PlayerAccess.Instance.GetPlayerId(order.zoneid, order.openid);
                PlayerBusiness player = PlayersProxy.FindPlayerByID(pid);
                if (player == null)
                {
                    return Send(client, OrderResult.InvalidUid);
                }

                order.Url = request.Url;
                if (!OrderAccess.Instance.NewOrder(order))
                {
                    return Send(client, OrderResult.OrderExists);
                }

                // 角色正确,状态由0变到11
                OrderAccess.Instance.IncOrderState(order.token, 0, 11);

                if (ResponseCompleted(client, order, player))
                {
                    return null;
                }
                return Send(client, OrderResult.OrderExists);
            }
            catch (System.Exception ex)
            {
                LogWrapper.Error(ex);
                return null;
            }
        }
Beispiel #3
0
        public override CompactResponse Process(Socket client, CompactRequest request)
        {
            CompactResponse response = new CompactResponse();
            response.Ret = 4;
            try
            {
                if (request.Queries == null || (!request.Url.StartsWith(m_path)))
                {
                    response.Msg = "404";
                    return response;
                }
                string sig, cmd, par, time;
                request.Queries.TryGetValue("sig", out sig);
                request.Queries.TryGetValue("cmd", out cmd);
                request.Queries.TryGetValue("par", out par);
                request.Queries.TryGetValue("time", out time);

                object ps = JsonDecoder<Variant>.DeserializeObject(par);

                if (callAddr == null)
                {
                    string test = MD5Helper.MD5Encrypt(cmd + par + time + ConfigLoader.Config.GMKey);
                    if (test != sig.ToUpper())
                    {
                        response.Msg = "验证错误";
                        return response;
                    }
                }
                else if (callAddr.Address != ((System.Net.IPEndPoint)(client.RemoteEndPoint)).Address.Address)
                {
                    response.Msg = "验证错误";
                    return response;
                }

                Notification note = new Notification(cmd, ps as IList);

                System.Text.StringBuilder sb = new System.Text.StringBuilder(128);
                sb.Append("IP:");
                sb.Append(client.RemoteEndPoint);
                sb.Append(" cmd:");
                sb.Append(note.Name);
                sb.Append(" par:");
                sb.Append(par);

                //写日志
                if (note.Name != GMCommand.Online)
                {
                    logger.Info(sb.ToString());
                }

                Func<Notification, object> fun;
                if (m_command.TryGetValue(cmd, out fun) ||
                    (ServerManager.AdminGM && m_adminCommand.TryGetValue(cmd, out fun)))
                {
                    if (fun != null)
                    {
                        object result = fun(note);
                        if (client.Connected)
                        {
                            string resultStr = JsonConvert.SerializeObject(result);
                            byte[] data = Encoding.UTF8.GetBytes(resultStr);
                            //client.Send(data);
                            //寫入資料本體
                            client.Send(new ArraySegment<byte>[]{
                                    new ArraySegment<byte>(CompactResponse.HttpOK),
                                    new ArraySegment<byte>(Encoding.UTF8.GetBytes(data.Length + "\r\n\r\n")),
                                    new ArraySegment<byte>(data)}
                                   );
                            client.Shutdown(SocketShutdown.Send);
                        }
                        return null;
                    }
                }
            }
            catch (System.Exception ex)
            {
                response.Msg = ex.Message;
                LogWrapper.Error(ex);
            }
            return response;
        }