Esempio n. 1
0
        public override void doResponse(OperationRequest operationRequest, SendParameters sendParameters, MyClientPeer peer)
        {
            Dictionary <byte, object> responseParameter = new Dictionary <byte, object>();

            try
            {
                //获取并查询用户
                Dictionary <byte, object> parameters = operationRequest.Parameters;
                String   userName   = (String)DictionaryUtils.getValue <byte, object>(parameters, (byte)ParameterCode.UserName);
                String   cardsSet   = (String)DictionaryUtils.getValue <byte, object>(parameters, (byte)ParameterCode.CardsSet);
                int      cardsSetId = (int)DictionaryUtils.getValue <byte, object>(parameters, (byte)ParameterCode.CardsSetId);
                String[] info       = cardsSet.Split(' ');
                CardsSet set        = new CardsSet();
                set.Name        = info[0];
                set.CardCapable = int.Parse(info[1]);
                set.Changeable  = bool.Parse(info[2]);
                set.Number      = int.Parse(info[3]);
                set.profession  = (Profession)int.Parse(info[4]);
                set.gameMode    = (GameMode)int.Parse(info[5]);
                for (int i = 0; i < set.Number; i++)
                {
                    set.cards[i]    = info[6 + 2 * i];
                    set.isGolden[i] = bool.Parse(info[7 + 2 * i]);
                }

                Application.logger.Info(cardsSetId + set.ToString());

                //用户卡组变化
                User user = DictionaryUtils.getValue <String, User>(Application.loginUserDict, userName);
                user.CardSets.Remove(cardsSetId);
                user.CardSets.Add(cardsSetId, set);

                //将变化保存到文件数据库
                UserManager.disassembleCardSetsInfo(user.UserName, user.CardSets);

                //保存用户
                Application.loginUserDict.Remove(user.UserName);
                Application.loginUserDict.Add(user.UserName, user);

                //封装信息
                responseParameter.Add((byte)ParameterCode.CardsSetOperationResult, 1);
            }
            catch (Exception e)
            {
                Application.logger.Info(e.ToString());
                responseParameter.Add((byte)ParameterCode.CardsSetOperationResult, 0);
            }

            OperationResponse response = new OperationResponse((byte)OPCode.ChangeCardsSet, responseParameter);

            peer.SendOperationResponse(response, sendParameters);
        }
Esempio n. 2
0
        //User字符串化
        public static String praseUserToUserString(User user)
        {
            String userString = user.UserName + ";" + user.Password + ";" + user.Money + ";" + user.ArcaneDust + ";";

            foreach (Series s in user.MyCardsPackage.Keys)
            {
                userString += (byte)s + ":" + DictionaryUtils.getValue <Series, int>(user.MyCardsPackage, s) + ",";
            }
            userString += ";";
            foreach (String s in user.MyCards.Keys)
            {
                userString += s + ":" + DictionaryUtils.getValue <String, int>(user.MyCards, s) + ",";
            }
            userString += ";";
            foreach (int s in user.CardSets.Keys)
            {
                CardsSet cardsSet = DictionaryUtils.getValue <int, CardsSet>(user.CardSets, s);
                if (cardsSet != null)
                {
                    userString += s + ":" + cardsSet.ToString() + ",";
                }
            }
            return(userString);
        }