Files
prestonbane/src/engine/net/client/handlers/GroupInviteHandler.java
T

136 lines
4.6 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
2024-02-15 19:46:41 -06:00
import engine.gameManager.ConfigManager;
import engine.gameManager.DispatchManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.GroupManager;
import engine.gameManager.SessionManager;
2024-05-12 11:55:12 -04:00
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
2022-04-30 09:41:17 -04:00
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.group.GroupInviteMsg;
import engine.net.client.msg.group.GroupUpdateMsg;
import engine.objects.Group;
2024-02-15 19:46:41 -06:00
import engine.objects.Guild;
2022-04-30 09:41:17 -04:00
import engine.objects.PlayerCharacter;
public class GroupInviteHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public GroupInviteHandler() {
2024-05-12 11:55:12 -04:00
super();
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private static Group createGroup(PlayerCharacter pc, ClientConnection origin) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (pc == null)
return null;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Group group = new Group(pc, GroupManager.incrGroupCount());
group.addGroupMember(pc);
GroupManager.addNewGroup(group);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
pc.setFollow(false);
// Send add self to group message
GroupUpdateMsg msg = new GroupUpdateMsg();
msg.setGroup(group);
msg.setPlayer(pc);
msg.setMessageType(1);
Dispatch dispatch = Dispatch.borrow(pc, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
group.addUpdateGroupJob();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return group;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// this can only be called if you already know you are not in a group
// and have issued an invite
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
2022-04-30 09:41:17 -04:00
2024-05-12 13:42:11 -04:00
ClientConnection origin) {
2023-07-15 09:23:48 -04:00
GroupInviteMsg msg = (GroupInviteMsg) baseMsg;
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (source == null)
return false;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Group group = GroupManager.getGroup(source);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Group is new, create it.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (group == null)
group = GroupInviteHandler.createGroup(source, origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (group == null)
return false;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (!group.isGroupLead(source)) // person doing invite must be group lead
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PlayerCharacter target = null;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (msg.getInvited() == 1) { // Use name for invite
target = SessionManager.getPlayerCharacterByLowerCaseName(msg.getName().toLowerCase());
} else { // Use ID for invite
target = SessionManager.getPlayerCharacterByID(msg.getTargetID());
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (target == null)
return false;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Client must be online
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (SessionManager.getClientConnection(target) == null)
return false;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (source == target) // Inviting self, so we're done
return false;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Skip invite if target is ignoring source
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (target.isIgnoringPlayer(source))
return false;
2022-04-30 09:41:17 -04:00
2024-04-28 11:58:55 -05:00
if (ConfigManager.MB_RULESET.getValue().equals("LORE")) {
2024-03-24 09:42:27 -04:00
if (source.guild.equals(Guild.getErrantGuild()))
2024-02-15 19:46:41 -06:00
return false;
2022-04-30 09:41:17 -04:00
2024-02-15 19:46:41 -06:00
if (source.guild.getGuildType() != null) {
if (source.guild.getGuildType().equals(target.guild.getGuildType()) == false)
return false;
}
}
2023-07-15 09:23:48 -04:00
// dont block invites to people already in a group and
// dont check for pending invites, the client does it
// Send invite message to target
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg.setSourceType(GameObjectType.PlayerCharacter.ordinal());
msg.setSourceID(source.getObjectUUID());
msg.setTargetType(0);
msg.setTargetID(0);
msg.setGroupType(GameObjectType.Group.ordinal());
msg.setGroupID(group.getObjectUUID());
msg.setInvited(1);
msg.setName(source.getFirstName());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Dispatch dispatch = Dispatch.borrow(target, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return true;
}
2022-04-30 09:41:17 -04:00
}