void ManagerBase::attach(Player* p, int id) { Seat* s = seat(id); if (!s) { throw Exception(ManagerBaseExcp, ErrorCode::InvalidSeat, "Invalid seat(%d)", id); } if (s->player()) { if (s->player() == p) { return; } throw Exception(ManagerBaseExcp, ErrorCode::SeatOccupied, "Current seat(%d) has been occupied", id); } detach(p); s->setPlayer(p); p->setSeat(id); attach((ManagerObserver*)p); notifyAttach(p, id); }
void ServPlayer::handle(Message* m) { if (m->type() == MsgType::Attach) { auto msg = m->get<AttachMsg>(); Seat* s = manager()->seat(msg->seat()); msg->set_self(s->player() == this); } mHdler->send(new Message(*m)); }
void ManagerBase::detach(Player* p) { int id = p->seat(); Seat* s = seat(id); if (s) { if (s->player() == p) { s->setPlayer(nullptr); } p->setSeat(NoneSeat); detach((ManagerObserver*)p); notifyDetach(p, id); } }