// <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)); } }
/** 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)); }
/** 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))); } }
/** 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())); } }