void Session::HandlePrivateMessage(ChatClientPrivateMessage* data) { Session* S = SearchForSession(data->receiver); if(S == NULL) { Send(ChatErrorMessage(CHAT_ERROR_RECEIVER_NOT_FOUND)); return; } else if(S->GetCharacter()->GetGuid() == m_char->GetGuid()) { Send(ChatErrorMessage(CHAT_ERROR_INTERIOR_MONOLOGUE)); return; } else if(S->GetBoolValue(BOOL_AWAY) || S->IsEnnemyWith(m_data[FLAG_GUID].intValue) || S->IsIgnoredWith(m_data[FLAG_GUID].intValue) || (S->GetBoolValue(BOOL_INVISIBLE) && !S->IsFriendWith(m_data[FLAG_GUID].intValue))) { std::vector<std::string> args; args.push_back(S->GetCharacter()->GetName()); Send(TextInformationMessage(1, 14, args)); return; } ChatServerMessage* distant = NULL; ChatServerCopyMessage* local = NULL; time_t t = time(NULL); if(data->GetOpcode() == CMSG_CHAT_CLIENT_PRIVATE) { distant = new ChatServerMessage(PSEUDO_CHANNEL_PRIVATE, data->content, static_cast<int>(t), "", m_char->GetGuid(), m_char->GetName(), m_data[FLAG_GUID].intValue); local = new ChatServerCopyMessage(PSEUDO_CHANNEL_PRIVATE, data->content, static_cast<int>(t), "", S->GetCharacter()->GetGuid(), S->GetCharacter()->GetName()); } else if(data->GetOpcode() == CMSG_CHAT_CLIENT_PRIVATE_WITH_OBJECT) { distant = new ChatServerWithObjectMessage(PSEUDO_CHANNEL_PRIVATE, data->content, static_cast<int>(t), "", m_char->GetGuid(), m_char->GetName(), m_data[FLAG_GUID].intValue, ((ChatClientPrivateWithObjectMessage*)data)->objects); local = new ChatServerCopyWithObjectMessage(PSEUDO_CHANNEL_PRIVATE, data->content, static_cast<int>(t), "", S->GetCharacter()->GetGuid(), S->GetCharacter()->GetName(), ((ChatClientPrivateWithObjectMessage*)data)->objects); } else return; S->Send(*distant); Send(*local); delete distant; delete local; }
void Session::HandlePartyInvitationRequestMessage(ByteBuffer& packet) { INIT_PARTY_LOCK PartyInvitationRequestMessage data; data.Deserialize(packet); std::string lower = Desperion::ToLowerCase(data.name); if(lower == Desperion::ToLowerCase(m_char->GetName()) || lower == m_data[FLAG_PSEUDO].stringValue) return; Session* S = SearchForSession(data.name); if(S == NULL) { Send(PartyCannotJoinErrorMessage(0, 1)); return; } else if(m_party != NULL && m_party->PlayersSize() + m_party->GuestsSize() >= 8) { Send(PartyCannotJoinErrorMessage(0, 3)); return; } for(std::map<int, Session*>::iterator it = S->m_partyInvitations.begin(); it != S->m_partyInvitations.end(); ++it) { if(it->second->GetData(FLAG_GUID).intValue == m_data[FLAG_GUID].intValue) { Send(PartyCannotJoinErrorMessage(0, 6)); return; } } if(m_party == NULL) { std::vector<PartyMemberInformationsPtr> members; members.push_back(PartyMemberInformationsPtr(m_char->GetPartyMemberInformations())); m_party = new Party; PARTY_LOCK(m_party) m_party->SetPartyId(static_cast<int>(RandomUInt())); m_party->SetLeader(this); Send(PartyJoinMessage(m_party->GetPartyId(), 0, m_char->GetGuid(), 8, members, std::vector<PartyGuestInformationsPtr>(), false)); } if(!lock) PARTY_LOCK(m_party) S->m_partyInvitations[m_party->GetPartyId()] = this; m_party->GuestPush(S); m_party->SetGuestHost(S->GetCharacter()->GetGuid(), m_char->GetGuid()); m_party->Send(PartyNewGuestMessage(m_party->GetPartyId(), S->GetCharacter()->GetPartyGuestInformations(m_data[FLAG_GUID].intValue))); S->Send(PartyInvitationMessage(m_party->GetPartyId(), 0, 8, m_char->GetGuid(), m_char->GetName(), S->GetCharacter()->GetGuid())); }
void Session::HandlePartyInvitationDetailsRequestMessage(ByteBuffer& packet) { INIT_PARTY_LOCK PartyInvitationDetailsRequestMessage data; data.Deserialize(packet); std::map<int, Session*>::iterator it = m_partyInvitations.find(data.partyId); if(it == m_partyInvitations.end()) return; Session* S = it->second; if(S->m_party == NULL) return; // ne devrait pas arriver grace aux locks std::vector<PartyInvitationMemberInformationsPtr> members; PARTY_LOCK(S->m_party) S->m_party->FillInvitationMembers(members); Send(PartyInvitationDetailsMessage(S->m_party->GetPartyId(), 0, it->first, S->GetCharacter()->GetName(), S->m_party->GetLeader()->GetCharacter()->GetGuid(), members)); }