Example #1
0
        /** Register the user onto a server.
         *
         * 用户注册/登录 (由于钱包功能尚不支持,Demo阶段暂时使用用户邮箱/密码作为认证方法。若有变动将在Global.VerifyUser()方法里变更实现)
         * 返回:该用户所有卡牌具体信息。若在该服务器上新账户,为用户新建若干卡牌。
         *
         * Check psw/signature first, then
         * If the user does exist already,
         *      If user exist on current server, consider as login in.
         *      If user does exist on another server, transfer user to this server.
         * Else, create cards for this user. Need attach some GAS...
         *
         * Return: S<header>
         *
         */
        private static byte[] Register(Credential credential, BigInteger serverId, string nickName, BigInteger iconID)
        {
            byte[] userData = RW.FindDataUser(credential.email);
            if (userData.Length != 0)
            {   //Exists
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.Duplicated));
            }
            else
            {
                byte[] psdHash = Hash256(Op.String2Bytes(credential.psw));
                User   user    = new User();
                user.address  = credential.address;
                user.email    = credential.email;
                user.pswHash  = psdHash;
                user.nickName = nickName;
                user.icon     = iconID;
                user.serverID = serverId;
                user.warID    = Op.Void();
                user.city     = Const.numCities;
                //user.cardIDs = new byte[0];

                RW.SaveUser(user);
                return(NuTP.RespDataSucWithBody(RW.User2Bytes(user)));
            }
        }
Example #2
0
        /* * NuTP:
         *
         * <RegCards> =  [S<header>, S[S<card>*]]
         *
         */
        private static byte[] RegCards(Credential credential, int num)
        {
            byte[] userData = RW.FindDataUser(credential.email);
            if (userData.Length == 0)
            {   //Account Not exist
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.NotExist));
            }
            else
            {   //Account does exist
                User user       = RW.Bytes2User(userData);
                int  numAlready = RW.NumCardsOfUser(user);
                int  numPending = Const.numCardsTotalReg - numAlready;
                if (numPending <= 0)
                {
                    return(NuTP.RespDataWithCode(ErrCate.Card, ErrType.Duplicated));
                }
                else
                {
                    CarryBattleSC.Card[] cardsNew  = GenerateRandomCards(user, (numPending < Const.numCardsPerReg) ? numPending : Const.numCardsPerReg);
                    CarryBattleSC.Card[] cardsOrig = user.cards;
                    user.cards = new CarryBattleSC.Card[cardsOrig.Length + cardsNew.Length];


                    for (int i = 0; i < cardsOrig.Length; i++)
                    {
                        user.cards[i] = cardsOrig[i];
                    }

                    for (int j = 0; j < cardsNew.Length; j++)
                    {
                        user.cards[j + cardsOrig.Length] = cardsNew[j];
                    }
                    //更新玩家数据
                    RW.SaveUser(user);

                    byte[] body = RW.UserCards2Table(user);
                    return(NuTP.RespDataSucWithBody(body));
                }
            }
        }