コード例 #1
0
        /** Get basic information of a list of users
         *
         *  获取一系列玩家信息, 内容包括所在服务器、所占城池、
         * 返回:该用户所有卡牌具体信息。
         *
         * For each user, the information includes:
         *     -  User email and address,
         *     -  User current server and city
         *     -  User score and unclaimed score
         *     -  User's cards (full cards data)
         *
         * Return: Array of the User objects and cards
         *
         *
         */

        /* * NuTP:
         * <emails> = S[S<email>*]
         *
         * <getUsers> =  [S<header>,
         *             S[([S<user>,
         *                  S[S<card>*10]]
         *             )*]
         */

        private static byte[] GetUsers(Credential credential, byte[] emails)
        {
            // This method does not require credential

            int numEmails = emails.SizeTable();

            byte[] retBody = Op.Void();

            for (int i = 0; i < numEmails; i++)
            {
                string email = emails.SplitTblStr(i);
                User   user  = RW.FindUser(email);
                if (user != null)
                {
                    byte[] body = NuSD.Seg(RW.User2Bytes(user)).AddSeg(RW.UserCards2Table(user));
                    retBody.AddSeg(body);
                }
                else
                {
                    return(NuTP.RespDataWithDetail(ErrCate.User, ErrType.NotExist, email, Op.Void()));
                }
            }

            NuTP.Response response = new NuTP.Response
            {
                header = new NuTP.Header
                {
                    domain = NuTP.SysDom,
                    code   = NuTP.Code.Success
                },

                body = retBody
            };
            return(NuTP.Response2Bytes(response));
        }
コード例 #2
0
        public void TestSegEmpty()
        {
            byte[] n = new byte[0];

            byte[] bData = NuSD.Seg(n);
            Assert.AreEqual(bData.Length, 1);
            Assert.AreEqual(bData[0], 0x00);
        }
コード例 #3
0
 public void TestSeg()
 {
     Assert.AreEqual(NuSD.Seg(body5), seg5);
     Assert.AreEqual(NuSD.Seg(body127), seg128);
     Assert.AreEqual(NuSD.Seg(body128), seg129);
     Assert.AreEqual(NuSD.Seg(body130), seg131);
     Assert.AreEqual(NuSD.Seg(body255), seg257);
     Assert.AreEqual(NuSD.Seg(body300), seg302);
 }
コード例 #4
0
 public static byte[] Quiz2Bytes(Quiz quiz)
 {
     byte[] ret  = NuSD.Seg(quiz.nameInquirer).AddSeg(quiz.nameAnswerer).AddSegStr(quiz.message);
     byte[] qids = Op.Void();
     for (int i = 0; i < quiz.questions.Length; i++)
     {
         qids = qids.AddSeg(Question2Bytes(quiz.questions[i]));
     }
     return(ret.AddSeg(qids));
 }
コード例 #5
0
        public static byte[] User2Bytes(User user)
        {
            byte[] dataCardIds = Op.Void();
            if (user.cards.Length > 0)
            {
                for (int i = 0; i < user.cards.Length; i++)
                {
                    //no cards data
                    dataCardIds = dataCardIds.AddSeg(user.cards[i].id);
                }
            }

            return(NuSD.Seg(user.id).AddSeg(dataCardIds));
        }
コード例 #6
0
 public static byte[] Player2Bytes(Player player)
 {
     return(NuSD.Seg(player.address)
            .AddSegInt(player.lvlAtk)
            .AddSegInt(player.lvlDef)
            .AddSegInt(player.lvlSpd)
            .AddSegInt(player.lvlHP)
            .AddSegInt(player.lvlRev)
            .AddSegInt(player.lastUpdateYear)
            .AddSegInt(player.water)
            .AddSegInt(player.soil)
            .AddSegInt(player.wind)
            .AddSegInt(player.fire));
 }
コード例 #7
0
 public static byte[] Card2Bytes(Card card)
 {
     if (card == null)
     {
         return(Op.Void());
     }
     else
     {
         return(NuSD.Seg(card.cardID)
                .AddSegInt(card.type)
                .AddSeg(card.lvls)
                .AddSegStr(card.ownerEmail)
                .AddSegInt(card.warPos));
     }
 }
コード例 #8
0
        public void TestDataDesegWithID()
        {
            //public static byte[] tableThree = { 5, 1, 2, 3, 4, 5, 2, 12, 2, 1, 0 };
            byte[] b1 = NuSD.DesegWithIdFromTable(tableThree, 0);
            byte[] b2 = NuSD.DesegWithIdFromTable(tableThree, 1);
            byte[] b3 = NuSD.DesegWithIdFromTable(tableThree, 2);

            byte[] seg = NuSD.Seg(tableThree);
            byte[] b4  = NuSD.DesegWithIdFromSeg(seg, 1);

            Assert.AreEqual(b1, new byte[] { 1, 2, 3, 4, 5 });
            Assert.AreEqual(b2, new byte[] { 12, 2 });
            Assert.AreEqual(b3, new byte[] { 0 });
            Assert.AreEqual(b4, new byte[] { 12, 2 });
        }
コード例 #9
0
 // Customized Serialization for Card.
 // The Class Neunity.Tools.NuSD Manages Serialization/Deserialization.
 // NuSD: <Card> = [S<id>,S<name>,S<birthBlock>,S<level>,S<ownerId>,S<isFighting#1>]
 public static byte[] Card2Bytes(Card card)
 {
     if (card == null)
     {
         return(Op.Void());
     }
     else
     {
         return(NuSD.Seg(card.id)
                .AddSegStr(card.name)
                .AddSegInt(card.birthBlock)
                .AddSegInt(card.level)
                .AddSeg(card.ownerId)
                .AddSegBool(card.isLive));
     }
 }
コード例 #10
0
        /** Get basic information of an user
         *
         *  获取一个玩家信息, 内容包括所在服务器、所占城池、
         * 返回:该用户所有卡牌具体信息。
         *
         * The information includes:
         *     -  User email and address,
         *     -  User current server and city
         *     -  User score and unclaimed score
         *     -  User's cards (full cards data)
         *
         * Return: Array of the User objects and cards
         *
         *
         */

        /* * NuTP:
         * <GetUsers> =  [S<header>, S<user>, S[S<card>*]]
         *
         */

        private static byte[] GetUser(Credential credential, string email)
        {
            // This method does not require credential

            User user = RW.FindUser(email);

            if (user != null)
            {
                byte[] body = NuSD.Seg(RW.User2Bytes(user)).AddSeg(RW.UserCards2Table(user));
                return(NuTP.RespDataSucWithBody(body));
            }
            else
            {
                return(NuTP.RespDataWithDetail(ErrCate.User, ErrType.NotExist, email, Op.Void()));
            }
        }
コード例 #11
0
 public void TestSeg()
 {
     Assert.AreEqual(NuSD.Seg(body5), seg5);
     Assert.AreEqual(NuSD.Seg(body300), seg302);
     Assert.AreEqual(NuSD.Seg(body255), seg257);
 }