Beispiel #1
0
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);
}
Beispiel #2
0
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));
}
Beispiel #3
0
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);
    }
}