PartyOperationHandler.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:8k
源码类别:

游戏

开发平台:

Java

  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. package net.sf.odinms.net.channel.handler;
  19. import java.rmi.RemoteException;
  20. import net.sf.odinms.client.MapleCharacter;
  21. import net.sf.odinms.client.MapleClient;
  22. import net.sf.odinms.net.AbstractMaplePacketHandler;
  23. import net.sf.odinms.net.channel.ChannelServer;
  24. import net.sf.odinms.net.world.MapleParty;
  25. import net.sf.odinms.net.world.MaplePartyCharacter;
  26. import net.sf.odinms.net.world.PartyOperation;
  27. import net.sf.odinms.net.world.remote.WorldChannelInterface;
  28. import net.sf.odinms.tools.MaplePacketCreator;
  29. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  30. public class PartyOperationHandler extends AbstractMaplePacketHandler {
  31.     @Override
  32.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  33.         c.getPlayer().resetAfkTime();
  34.         int operation = slea.readByte();
  35.         MapleCharacter player = c.getPlayer();
  36.         WorldChannelInterface wci = ChannelServer.getInstance(c.getChannel()).getWorldInterface();
  37.         MapleParty party = player.getParty();
  38.         MaplePartyCharacter partyplayer = new MaplePartyCharacter(player);
  39.         switch (operation) {
  40.             case 1: { // create
  41.                 if (c.getPlayer().getParty() == null) {
  42.                     try {
  43.                         party = wci.createParty(partyplayer);
  44.                         player.setParty(party);
  45.                     } catch (RemoteException e) {
  46.                         c.getChannelServer().reconnectWorld();
  47.                     }
  48.                     c.getSession().write(MaplePacketCreator.partyCreated());
  49.                 } else {
  50.                     c.getSession().write(MaplePacketCreator.serverNotice(5, "You can't create a party as you are already in one"));
  51.                 }
  52.                 break;
  53.             }
  54.             case 2: { // leave
  55.                 if (party != null) { //are we in a party? o.O"
  56.                     try {
  57.                         if (partyplayer.equals(party.getLeader())) { // disband
  58.                             wci.updateParty(party.getId(), PartyOperation.DISBAND, partyplayer);
  59.                             if (player.getEventInstance() != null) {
  60.                                 player.getEventInstance().disbandParty();
  61.                             }
  62.                         } else {
  63.                             wci.updateParty(party.getId(), PartyOperation.LEAVE, partyplayer);
  64.                             if (player.getEventInstance() != null) {
  65.                                 player.getEventInstance().leftParty(player);
  66.                             }
  67.                         }
  68.                     } catch (RemoteException e) {
  69.                         c.getChannelServer().reconnectWorld();
  70.                     }
  71.                     player.setParty(null);
  72.                 }
  73.                 break;
  74.             }
  75.             case 3: { // accept invitation
  76.                 int partyid = slea.readInt();
  77.                 if (c.getPlayer().getParty() == null) {
  78.                     try {
  79.                         party = wci.getParty(partyid);
  80.                         if (party != null) {
  81.                             if (party.getMembers().size() < 6) {
  82.                                 wci.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
  83.                                 player.receivePartyMemberHP();
  84.                                 player.updatePartyMemberHP();
  85.                             } else {
  86.                                 c.getSession().write(MaplePacketCreator.partyStatusMessage(17));
  87.                             }
  88.                         } else {
  89.                             c.getSession().write(MaplePacketCreator.serverNotice(5, "The party you are trying to join does not exist"));
  90.                         }
  91.                     } catch (RemoteException e) {
  92.                         c.getChannelServer().reconnectWorld();
  93.                     }
  94.                 } else {
  95.                     c.getSession().write(MaplePacketCreator.serverNotice(5, "You can't join the party as you are already in one"));
  96.                 }
  97.                 break;
  98.             }
  99.             case 4: { // invite
  100.                 //TODO store pending invitations and check against them
  101.                 String name = slea.readMapleAsciiString();
  102.                 MapleCharacter invited = c.getChannelServer().getPlayerStorage().getCharacterByName(name);
  103.                 if (invited != null) {
  104.                     if (invited.getParty() == null) {
  105.                         if (party.getMembers().size() < 6) {
  106.                             invited.getClient().getSession().write(MaplePacketCreator.partyInvite(player));
  107.                         } else {
  108.                             c.getSession().write(MaplePacketCreator.partyStatusMessage(16));
  109.                         }
  110.                     } else {
  111.                         c.getSession().write(MaplePacketCreator.partyStatusMessage(17));
  112.                     }
  113.                 } else {
  114.                     c.getSession().write(MaplePacketCreator.partyStatusMessage(19));
  115.                 }
  116.                 break;
  117.             }
  118.             case 5: { // expel
  119.                 int cid = slea.readInt();
  120.                 if (partyplayer.equals(party.getLeader())) {
  121.                     MaplePartyCharacter expelled = party.getMemberById(cid);
  122.                     if (expelled != null) {
  123.                         try {
  124.                             wci.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
  125.                             if (player.getEventInstance() != null) {
  126.                                 /*if leader wants to boot someone, then the whole party gets expelled
  127.                                 TODO: Find an easier way to get the character behind a MaplePartyCharacter
  128.                                 possibly remove just the expellee.*/
  129.                                 if (expelled.isOnline()) {
  130.                                     player.getEventInstance().disbandParty();
  131.                                 }
  132.                             }
  133.                         } catch (RemoteException e) {
  134.                             c.getChannelServer().reconnectWorld();
  135.                         }
  136.                     }
  137.                 }
  138.                 break;
  139.             }
  140.             case 6: {
  141.                 int newLeader = slea.readInt();
  142.                 MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
  143.                 try {
  144.                     party.setLeader(newLeadr);
  145.                     wci.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
  146.                 } catch (RemoteException suckme) {
  147.                     c.getChannelServer().reconnectWorld();
  148.                 }
  149.                 break;
  150.             }
  151.         }
  152.     }
  153. }