/** 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)); }
/** 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())); } }
/** The Logic of merging the cards. The rule is: * 0. Two cards has to share the same owner * 1. Card1 has higher level than Card2 * 2. Card1 and Card2 should have the same */ public static byte[] CardMerge(byte[] cardID1, byte[] cardID2, string name) { Card card1 = ReadCard(cardID1); if (card1 == null) { return(NuTP.RespDataWithDetail(Error.Dom, Error.NoExist, Op.Bytes2String(cardID1), Op.Void())); } Card card2 = ReadCard(cardID2); if (card2 == null) { return(NuTP.RespDataWithDetail(Error.Dom, Error.NoExist, Op.Bytes2String(cardID2), Op.Void())); } if (Op.Bytes2BigInt(card1.ownerId) != Op.Bytes2BigInt(card2.ownerId)) { return(NuTP.RespDataWithCode(Error.Dom, Error.DiffOwner)); } if (card1.level >= card2.level) { BigInteger newLevel = card1.level + card2.level; Card newCard = new Card { id = Hash256(Op.JoinTwoByteArray(card1.id, card2.id)), name = name, level = newLevel, birthBlock = Blockchain.GetHeight(), ownerId = card1.ownerId, isLive = true }; SaveCard(newCard); card1.isLive = false; card2.isLive = false; SaveCard(card1); SaveCard(card2); return(NuTP.RespDataSucWithBody(Card2Bytes(newCard))); } else { return(NuTP.RespDataWithCode(Error.Dom, Error.LvInvalid)); } }