/** 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)); }
/** All the completed wars related with particular user with "maximum" recent items. * * 获取某用户已完成战役列表(最近的maximum个)。返回:一组War的列表 * * * Return: Array of War Object */ private static byte[] GetUserSeiges(Credential credential, string email, BigInteger maximum) { User user = RW.FindUser(email); BigInteger tot = RW.NumUserSiegeHistory(user); BigInteger num = (tot > maximum) ? maximum : tot; return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.ServiceUnavailable)); }
/** User starts a war against a city. If the city is empty now, it's gonna occupy it directly. * 参战某城市, * Return: An object of War. If failed to create, return null */ /** User starts a war against a city. If the city is empty now, it's gonna occupy it directly. * 参战某城市, * Return: An object of War. If failed to create, return null */ public static byte[] StartSiege(Credential credential, BigInteger serverId, BigInteger cityId, byte[] cardIds) { if (Global.VerifyUser(credential)) { if (cityId >= Const.numCities) { return(NuTP.RespDataWithCode(ErrCate.City, ErrType.NotExist)); } else { //City does exist City city = RW.FindCity(serverId, cityId); BigInteger status = RW.GetStatusCity(city); if (status == StatusCity.Sieging) { return(NuTP.RespDataWithCode(ErrCate.City, ErrType.Duplicated)); } else { User user = RW.FindUser(credential.email); if (user.warID != Op.Void()) { //User does not allow to participate into multiple wars at the same time return(NuTP.RespDataWithCode(ErrCate.War, ErrType.Duplicated)); } else { CarryBattleSC.Card[] cards = RW.Table2Cards(cardIds); if (cards.Length != Const.numCardsSiege) { //Format of card array must be wrong return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.BadRequest)); } for (int i = 0; i < Const.numCardsSiege; i++) { if (cards[i].ownerEmail != user.email) { return(NuTP.RespDataWithCode(ErrCate.Card, ErrType.NotExist)); } } Siege siege = RW.CreateSiege(serverId, city, user, cards, Blockchain.GetHeight()); return(NuTP.RespDataSucWithBody(RW.Seige2Bytes(siege))); } } } } else { return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail)); } }
/** 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())); } }
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)); } }