Exemplo n.º 1
0
def make_room(users):
    owner, users = users_random_pop(users)
    gr = GeneralRecord(int(time.time()), u"#たまひよ", tama._pick_room_number(), owner.name)
    gr.game_ipaddr = u"127.0.0.1"
    db_session.add(gr)
    db_session.flush()
    pr = PersonalRecord(owner.id, gr.id)
    db_session.add(pr)
    db_session.flush()
    return gr.id, owner, users
Exemplo n.º 2
0
  def make_room(self, json):
    """部屋作成、更新"""
    args = loads(json)
    print args

    # 登録されたuserでなければならない
    user = self._whoami(args["caller"])
    if user is None:
      return dumps((False,))

    # ホスト以外はどの部屋にも入っていない状態でなければ使えない
    owner_pr = self._is_room_owner(args["channel"], args["caller"])
    pr = self._get_active_pr(user)
    if bool(pr) and (not bool(owner_pr)):
      return dumps((False,))

    if owner_pr:
      gr = owner_pr.general_record
      gr.room_name = args["room_name"]
      gr.rate_limit = args["rate_limit"]
      db_session.flush()
    else:
      gr = GeneralRecord(int(time.time()), args["channel"], self._pick_room_number(), user.name)
      gr.room_name = args["room_name"]
      gr.rate_limit = args["rate_limit"]
      gr.game_ipaddr = args["ip_addr"]
      db_session.add(gr)
      db_session.flush()
      self._join_to_room(user, gr)
    self._save_session(args["hostname"], user)
    db_session.commit()
    params = self._construct_room_info(gr, user)
    session_diff = self._diff_session(user)
    if session_diff:
      params.update({"session_diff": session_diff})
    return dumps((True, params))