Exemple #1
0
        // <emails> = [S<email>*]
        //<FakeUsers> = [S<user>*]
        private static byte[] FakeUsers(BigInteger serverId, byte[] emails)
        {
            byte[] body = Op.Void();

            if (Runtime.CheckWitness(Owner))
            {
                int numEmails = emails.SizeTable();
                for (int i = 0; i < numEmails; i++)
                {
                    string email = NuSD.SplitTblStr(emails, i);
                    User   user  = new User
                    {
                        address  = Op.Void(),
                        email    = email,
                        pswHash  = Op.Void(),
                        nickName = "Fake",
                        icon     = 0,
                        serverID = serverId,
                        warID    = Op.Void(),
                        city     = Const.numCities
                    };
                    user.cards = GenerateRandomCards(user, 10);
                    RW.SaveUser(user);
                    body.AddSeg(RW.User2Bytes(user));
                }

                return(NuTP.RespDataSucWithBody(body));
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }
Exemple #2
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)));
            }
        }
Exemple #3
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));
                }
            }
        }
Exemple #4
0
        private static byte[] FakeOccupies(BigInteger serverId, string email, BigInteger cityID)
        {
            if (Runtime.CheckWitness(Owner))
            {
                if (cityID > Const.numCities || cityID <= 0)
                {
                    return(NuTP.RespDataWithCode(ErrCate.City, ErrType.NotExist));
                }
                else
                {
                    User user = RW.FindUser(email);
                    if (user != null)
                    {
                        City city = RW.FindCity(serverId, cityID);
                        if (city.ownerID.Length == 0 || city.ownerID.Length == 1) //something wrong with bytes2string/string2bytes
                        {                                                         //not work when it's not occupied
                            city.ownerID = email;
                            RW.SaveCity(serverId, city);

                            user.city = cityID;
                            RW.SaveUser(user);
                            return(NuTP.RespDataSuccess());
                        }
                        else
                        {
                            return(NuTP.RespDataWithCode(ErrCate.City, ErrType.Duplicated));
                        }
                    }
                    else
                    {
                        return(NuTP.RespDataWithCode(ErrCate.User, ErrType.NotExist));
                    }
                }
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }