2020-10-04 23:54:08 +00:00
|
|
|
#include "CNShardServer.hpp"
|
|
|
|
#include "CNStructs.hpp"
|
|
|
|
#include "ChatManager.hpp"
|
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
#include "GroupManager.hpp"
|
2020-10-09 00:01:35 +00:00
|
|
|
#include "NanoManager.hpp"
|
2020-10-04 23:54:08 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <chrono>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
void GroupManager::init() {
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GROUP_INVITE, requestGroup);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GROUP_INVITE_REFUSE, refuseGroup);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GROUP_JOIN, joinGroup);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GROUP_LEAVE, leaveGroup);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE, chatGroup);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE, menuChatGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::requestGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_GROUP_INVITE))
|
|
|
|
return; // malformed packet
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_CL2FE_REQ_PC_GROUP_INVITE* recv = (sP_CL2FE_REQ_PC_GROUP_INVITE*)data->buf;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-10-04 23:54:08 +00:00
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_To);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr || otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
// fail if the group is full or the other player is already in a group
|
|
|
|
if (plr->groupCnt >= 4 || otherPlr->groupCnt > 1) {
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE_FAIL, resp);
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_INVITE_FAIL, sizeof(sP_FE2CL_PC_GROUP_INVITE_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
|
|
|
CNSocket* otherSock = PlayerManager::getSockFromID(recv->iID_To);
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (otherSock == nullptr)
|
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE, resp);
|
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
resp.iHostID = plr->iIDGroup;
|
2020-10-04 23:54:08 +00:00
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
otherSock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_INVITE, sizeof(sP_FE2CL_PC_GROUP_INVITE));
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::refuseGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_GROUP_INVITE_REFUSE))
|
|
|
|
return; // malformed packet
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_CL2FE_REQ_PC_GROUP_INVITE_REFUSE* recv = (sP_CL2FE_REQ_PC_GROUP_INVITE_REFUSE*)data->buf;
|
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
CNSocket* otherSock = PlayerManager::getSockFromID(recv->iID_From);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (otherSock == nullptr)
|
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE_REFUSE, resp);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
resp.iID_To = plr->iID;
|
|
|
|
|
2020-10-21 05:24:51 +00:00
|
|
|
otherSock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_INVITE_REFUSE, sizeof(sP_FE2CL_PC_GROUP_INVITE_REFUSE));
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_GROUP_JOIN))
|
|
|
|
return; // malformed packet
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_CL2FE_REQ_PC_GROUP_JOIN* recv = (sP_CL2FE_REQ_PC_GROUP_JOIN*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_From);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr || otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
// fail if the group is full or the other player is already in a group
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr->groupCnt > 1 || plr->iIDGroup != plr->iID || otherPlr->groupCnt >= 4) {
|
2020-10-09 16:24:16 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_JOIN_FAIL, resp);
|
2020-10-04 23:54:08 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_JOIN_FAIL, sizeof(sP_FE2CL_PC_GROUP_JOIN_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_JOIN), otherPlr->groupCnt + 1, sizeof(sPCGroupMemberInfo))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_JOIN packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
int bitFlagBefore = getGroupFlags(otherPlr);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
plr->iIDGroup = otherPlr->iID;
|
|
|
|
otherPlr->groupCnt += 1;
|
|
|
|
otherPlr->groupIDs[otherPlr->groupCnt-1] = plr->iID;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_GROUP_JOIN) + otherPlr->groupCnt * sizeof(sPCGroupMemberInfo);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
memset(respbuf, 0, resplen);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_FE2CL_PC_GROUP_JOIN *resp = (sP_FE2CL_PC_GROUP_JOIN*)respbuf;
|
|
|
|
sPCGroupMemberInfo *respdata = (sPCGroupMemberInfo*)(respbuf+sizeof(sP_FE2CL_PC_GROUP_JOIN));
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
resp->iID_NewMember = plr->iID;
|
|
|
|
resp->iMemberPCCnt = otherPlr->groupCnt;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
int bitFlag = getGroupFlags(otherPlr);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
for (int i = 0; i < otherPlr->groupCnt; i++) {
|
|
|
|
Player* varPlr = PlayerManager::getPlayerFromID(otherPlr->groupIDs[i]);
|
2020-10-09 00:01:35 +00:00
|
|
|
CNSocket* sockTo = PlayerManager::getSockFromID(otherPlr->groupIDs[i]);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
if (varPlr == nullptr || sockTo == nullptr)
|
2020-10-04 23:54:08 +00:00
|
|
|
continue;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
respdata[i].iPC_ID = varPlr->iID;
|
|
|
|
respdata[i].iPCUID = varPlr->PCStyle.iPC_UID;
|
|
|
|
respdata[i].iNameCheck = varPlr->PCStyle.iNameCheck;
|
|
|
|
memcpy(respdata[i].szFirstName, varPlr->PCStyle.szFirstName, sizeof(varPlr->PCStyle.szFirstName));
|
|
|
|
memcpy(respdata[i].szLastName, varPlr->PCStyle.szLastName, sizeof(varPlr->PCStyle.szLastName));
|
|
|
|
respdata[i].iSpecialState = varPlr->iSpecialState;
|
|
|
|
respdata[i].iLv = varPlr->level;
|
|
|
|
respdata[i].iHP = varPlr->HP;
|
|
|
|
respdata[i].iMaxHP = PC_MAXHEALTH(varPlr->level);
|
|
|
|
//respdata[i].iMapType = 0;
|
|
|
|
//respdata[i].iMapNum = 0;
|
|
|
|
respdata[i].iX = varPlr->x;
|
|
|
|
respdata[i].iY = varPlr->y;
|
|
|
|
respdata[i].iZ = varPlr->z;
|
|
|
|
// client doesnt read nano data here
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
NanoManager::nanoChangeBuff(sockTo, varPlr, bitFlagBefore | varPlr->iConditionBitFlag, bitFlag | varPlr->iConditionBitFlag);
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sendToGroup(otherPlr, (void*)&respbuf, P_FE2CL_PC_GROUP_JOIN, resplen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::leaveGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr)
|
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
groupKickPlayer(plr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::chatGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE))
|
|
|
|
return; // malformed packet
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-31 20:31:25 +00:00
|
|
|
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat));
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr || otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
// send to client
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp);
|
2020-10-31 20:31:25 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
2020-10-04 23:54:08 +00:00
|
|
|
resp.iSendPCID = plr->iID;
|
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sendToGroup(otherPlr, (void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC));
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
void GroupManager::menuChatGroup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE))
|
2020-10-21 05:24:51 +00:00
|
|
|
return; // malformed packet
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-31 20:31:25 +00:00
|
|
|
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat));
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (plr == nullptr || otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
// send to client
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);
|
2020-10-31 20:31:25 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
2020-10-04 23:54:08 +00:00
|
|
|
resp.iSendPCID = plr->iID;
|
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sendToGroup(otherPlr, (void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::sendToGroup(Player* plr, void* buf, uint32_t type, size_t size) {
|
|
|
|
for (int i = 0; i < plr->groupCnt; i++) {
|
2020-10-05 00:03:13 +00:00
|
|
|
CNSocket* sock = PlayerManager::getSockFromID(plr->groupIDs[i]);
|
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (sock == nullptr)
|
|
|
|
continue;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (type == P_FE2CL_PC_GROUP_LEAVE_SUCC) {
|
2020-10-05 00:03:13 +00:00
|
|
|
Player* leavingPlr = PlayerManager::getPlayer(sock);
|
2020-10-04 23:54:08 +00:00
|
|
|
leavingPlr->iIDGroup = leavingPlr->iID;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sock->sendPacket(buf, type, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupManager::groupTickInfo(Player* plr) {
|
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_MEMBER_INFO), plr->groupCnt, sizeof(sPCGroupMemberInfo))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_JOIN packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_GROUP_MEMBER_INFO) + plr->groupCnt * sizeof(sPCGroupMemberInfo);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
memset(respbuf, 0, resplen);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_FE2CL_PC_GROUP_MEMBER_INFO *resp = (sP_FE2CL_PC_GROUP_MEMBER_INFO*)respbuf;
|
|
|
|
sPCGroupMemberInfo *respdata = (sPCGroupMemberInfo*)(respbuf+sizeof(sP_FE2CL_PC_GROUP_MEMBER_INFO));
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
resp->iID = plr->iID;
|
|
|
|
resp->iMemberPCCnt = plr->groupCnt;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
for (int i = 0; i < plr->groupCnt; i++) {
|
|
|
|
Player* varPlr = PlayerManager::getPlayerFromID(plr->groupIDs[i]);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (varPlr == nullptr)
|
|
|
|
continue;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
respdata[i].iPC_ID = varPlr->iID;
|
|
|
|
respdata[i].iPCUID = varPlr->PCStyle.iPC_UID;
|
|
|
|
respdata[i].iNameCheck = varPlr->PCStyle.iNameCheck;
|
|
|
|
memcpy(respdata[i].szFirstName, varPlr->PCStyle.szFirstName, sizeof(varPlr->PCStyle.szFirstName));
|
|
|
|
memcpy(respdata[i].szLastName, varPlr->PCStyle.szLastName, sizeof(varPlr->PCStyle.szLastName));
|
|
|
|
respdata[i].iSpecialState = varPlr->iSpecialState;
|
|
|
|
respdata[i].iLv = varPlr->level;
|
|
|
|
respdata[i].iHP = varPlr->HP;
|
|
|
|
respdata[i].iMaxHP = PC_MAXHEALTH(varPlr->level);
|
|
|
|
//respdata[i].iMapType = 0;
|
|
|
|
//respdata[i].iMapNum = 0;
|
|
|
|
respdata[i].iX = varPlr->x;
|
|
|
|
respdata[i].iY = varPlr->y;
|
|
|
|
respdata[i].iZ = varPlr->z;
|
|
|
|
if (varPlr->activeNano > 0) {
|
|
|
|
respdata[i].bNano = 1;
|
|
|
|
respdata[i].Nano = varPlr->Nanos[varPlr->activeNano];
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sendToGroup(plr, (void*)&respbuf, P_FE2CL_PC_GROUP_MEMBER_INFO, resplen);
|
|
|
|
}
|
|
|
|
|
2020-10-19 17:26:14 +00:00
|
|
|
void GroupManager::groupKickPlayer(Player* plr) {
|
2020-10-04 23:54:08 +00:00
|
|
|
// if you are the group leader, destroy your own group and kick everybody
|
|
|
|
if (plr->iID == plr->iIDGroup) {
|
2020-10-09 00:01:35 +00:00
|
|
|
groupUnbuff(plr);
|
2020-10-04 23:54:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_LEAVE_SUCC, resp1);
|
|
|
|
sendToGroup(plr, (void*)&resp1, P_FE2CL_PC_GROUP_LEAVE_SUCC, sizeof(sP_FE2CL_PC_GROUP_LEAVE_SUCC));
|
2020-10-05 00:03:13 +00:00
|
|
|
plr->groupCnt = 1;
|
2020-10-04 23:54:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (otherPlr == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_LEAVE), otherPlr->groupCnt - 1, sizeof(sPCGroupMemberInfo))) {
|
|
|
|
std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_LEAVE packet size\n";
|
|
|
|
return;
|
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
size_t resplen = sizeof(sP_FE2CL_PC_GROUP_LEAVE) + (otherPlr->groupCnt - 1) * sizeof(sPCGroupMemberInfo);
|
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
memset(respbuf, 0, resplen);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sP_FE2CL_PC_GROUP_LEAVE *resp = (sP_FE2CL_PC_GROUP_LEAVE*)respbuf;
|
|
|
|
sPCGroupMemberInfo *respdata = (sPCGroupMemberInfo*)(respbuf+sizeof(sP_FE2CL_PC_GROUP_LEAVE));
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
resp->iID_LeaveMember = plr->iID;
|
|
|
|
resp->iMemberPCCnt = otherPlr->groupCnt - 1;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
int bitFlagBefore = getGroupFlags(otherPlr);
|
|
|
|
int bitFlag = bitFlagBefore & ~plr->iGroupConditionBitFlag;
|
2020-10-04 23:54:08 +00:00
|
|
|
int moveDown = 0;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
for (int i = 0; i < otherPlr->groupCnt; i++) {
|
|
|
|
Player* varPlr = PlayerManager::getPlayerFromID(otherPlr->groupIDs[i]);
|
2020-10-09 00:01:35 +00:00
|
|
|
CNSocket* sockTo = PlayerManager::getSockFromID(otherPlr->groupIDs[i]);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
if (varPlr == nullptr || sockTo == nullptr)
|
2020-10-04 23:54:08 +00:00
|
|
|
continue;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (moveDown == 1)
|
|
|
|
otherPlr->groupIDs[i-1] = otherPlr->groupIDs[i];
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
respdata[i-moveDown].iPC_ID = varPlr->iID;
|
|
|
|
respdata[i-moveDown].iPCUID = varPlr->PCStyle.iPC_UID;
|
|
|
|
respdata[i-moveDown].iNameCheck = varPlr->PCStyle.iNameCheck;
|
|
|
|
memcpy(respdata[i-moveDown].szFirstName, varPlr->PCStyle.szFirstName, sizeof(varPlr->PCStyle.szFirstName));
|
|
|
|
memcpy(respdata[i-moveDown].szLastName, varPlr->PCStyle.szLastName, sizeof(varPlr->PCStyle.szLastName));
|
|
|
|
respdata[i-moveDown].iSpecialState = varPlr->iSpecialState;
|
|
|
|
respdata[i-moveDown].iLv = varPlr->level;
|
|
|
|
respdata[i-moveDown].iHP = varPlr->HP;
|
|
|
|
respdata[i-moveDown].iMaxHP = PC_MAXHEALTH(varPlr->level);
|
2020-10-19 17:26:14 +00:00
|
|
|
// respdata[i-moveDown]].iMapType = 0;
|
|
|
|
// respdata[i-moveDown]].iMapNum = 0;
|
2020-10-04 23:54:08 +00:00
|
|
|
respdata[i-moveDown].iX = varPlr->x;
|
|
|
|
respdata[i-moveDown].iY = varPlr->y;
|
|
|
|
respdata[i-moveDown].iZ = varPlr->z;
|
|
|
|
// client doesnt read nano data here
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (varPlr == plr) {
|
|
|
|
moveDown = 1;
|
|
|
|
otherPlr->groupIDs[i] = 0;
|
2020-10-09 00:01:35 +00:00
|
|
|
NanoManager::nanoChangeBuff(sockTo, varPlr, bitFlagBefore | varPlr->iConditionBitFlag, varPlr->iConditionBitFlag);
|
|
|
|
} else
|
|
|
|
NanoManager::nanoChangeBuff(sockTo, varPlr, bitFlagBefore | varPlr->iConditionBitFlag, bitFlag | varPlr->iConditionBitFlag);
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
plr->iIDGroup = plr->iID;
|
|
|
|
otherPlr->groupCnt -= 1;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
sendToGroup(otherPlr, (void*)&respbuf, P_FE2CL_PC_GROUP_LEAVE, resplen);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
CNSocket* sock = PlayerManager::getSockFromID(plr->iID);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
if (sock == nullptr)
|
2020-10-21 05:24:51 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_GROUP_LEAVE_SUCC, resp1);
|
|
|
|
sock->sendPacket((void*)&resp1, P_FE2CL_PC_GROUP_LEAVE_SUCC, sizeof(sP_FE2CL_PC_GROUP_LEAVE_SUCC));
|
|
|
|
}
|
2020-10-09 00:01:35 +00:00
|
|
|
|
|
|
|
void GroupManager::groupUnbuff(Player* plr) {
|
|
|
|
int bitFlag = getGroupFlags(plr);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
for (int i = 0; i < plr->groupCnt; i++) {
|
|
|
|
CNSocket* sock = PlayerManager::getSockFromID(plr->groupIDs[i]);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
if (sock == nullptr)
|
|
|
|
continue;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
Player* otherPlr = PlayerManager::getPlayer(sock);
|
|
|
|
NanoManager::nanoChangeBuff(sock, otherPlr, bitFlag | otherPlr->iConditionBitFlag, otherPlr->iConditionBitFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupManager::getGroupFlags(Player* plr) {
|
|
|
|
int bitFlag = 0;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
for (int i = 0; i < plr->groupCnt; i++) {
|
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->groupIDs[i]);
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
if (otherPlr == nullptr)
|
|
|
|
continue;
|
2020-10-19 17:26:14 +00:00
|
|
|
|
|
|
|
bitFlag |= otherPlr->iGroupConditionBitFlag;
|
2020-10-09 00:01:35 +00:00
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-10-09 00:01:35 +00:00
|
|
|
return bitFlag;
|
2020-10-19 17:26:14 +00:00
|
|
|
}
|