return True def get_storage(): resp = s_storage.get(game.usertoken, game.storage) if resp.had_errors: return None return resp.content def create_storage(usertoken): cs = json.dumps(get_clean_storage()) resp = s_storage.create_if_not_exist(usertoken, game.storage, cs) with game_api.context("login"): @game_api.add() def login(username, password): if not server.is_online(): return "server is not online now, retry later" response = s_login(username, password) if response.had_errors: return "login failed, " + response.error_desc usertoken = response.content game.username = username game.usertoken = usertoken game.context = "lobby" create_storage(usertoken) return "logged successful" @game_api.add(name="help")
import shelve from pyapimaker import PyApi from config import config storage = PyApi() db_dir = config.get("db_dir", ".") users = shelve.open(db_dir + "/users.db") with storage.context("users"): @storage.add() def get(name): return users.get(name, None) @storage.add() def put(name, user): users[name] = user users.sync() @storage.add() def rem(name): del users[name] users.sync() profiles = shelve.open(db_dir + "/profiles.db") with storage.context("profiles"): @storage.add()
return True def get_storage(): resp = s_storage.get(game.usertoken, game.storage) if resp.had_errors: return None return resp.content def create_storage(usertoken): cs = json.dumps(get_clean_storage()) resp = s_storage.create_if_not_exist(usertoken, game.storage, cs) with game_api.context("login"): @game_api.add() def login(username, password): if not server.is_online(): return "server is not online now, retry later" response = s_login(username, password) if response.had_errors: return "login failed, " + response.error_desc usertoken = response.content game.username = username game.usertoken = usertoken game.context = "lobby" create_storage(usertoken) return "logged successful"
import shelve from pyapimaker import PyApi from config import config storage = PyApi() db_dir = config.get("db_dir", ".") users = shelve.open(db_dir + "/users.db") with storage.context("users"): @storage.add() def get(name): return users.get(name, None) @storage.add() def put(name, user): users[name] = user users.sync() @storage.add() def rem(name): del users[name] users.sync() profiles = shelve.open(db_dir + "/profiles.db") with storage.context("profiles"): @storage.add() def get(name): return profiles.get(name, {})