Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.7 kB
2
Indexable
Never
package ballistickemu.Lobby.handlers;

import ballistickemu.Lobby.LobbyServer;
import ballistickemu.Main;
import ballistickemu.Tools.StickPacketMaker;
import ballistickemu.Tools.StringTool;
import ballistickemu.Types.StickClient;
import ballistickemu.Types.StickClientRegistry;
import ballistickemu.Types.StickRoom;
import ballistickemu.Types.StickRoomRegistry;
import java.io.PrintStream;
import java.util.LinkedHashMap;



public class CreateRoomHandler
{
  public static void HandlePacket(StickClient client, String Packet)
  {
    try
    {
      String RoomData = "";
      String[] VIPList = new String[0];
      Boolean IsLabPass = Boolean.valueOf(false);
      if (Packet.indexOf(";", 0) > 0)
      {
        RoomData = StringTool.GetStringBetween(Packet, ";");
        VIPList = StringTool.GetStringBetween(Packet, ";", "\000").split(";");
        IsLabPass = Boolean.valueOf(true);
      }
      else {
        RoomData = Packet;
      }
      String mapID = RoomData.substring(2, 3);
      int cycleMode = Integer.parseInt(RoomData.substring(3, 4));
      Boolean isPrivate = Boolean.valueOf(RoomData.substring(4, 5).equalsIgnoreCase("1"));
      Boolean requiresLabPass = Boolean.valueOf(RoomData.substring(5, 6).equalsIgnoreCase("1"));
      String RoomName = RoomData.substring(6).replace("\000", "");
      
      LinkedHashMap<String, StickClient> VIPMap = new LinkedHashMap();
      
      if ((IsLabPass.booleanValue()) && (VIPList.length > 0))
      {
        for (String s : VIPList)
        {
          if (VIPList.length > 0)
          {
            if (Main.getLobbyServer().getClientRegistry().UIDExists(s).booleanValue()) {
              VIPMap.put(s, Main.getLobbyServer().getClientRegistry().getClientfromUID(s));
            }
          }
        }
      }
      

      if (client.getName() == null) {
        client.setUpAsQuickplay();
      } else {
        client.setQuickplayStatus(Boolean.valueOf(false));
      }
      StickRoom newRoom = new StickRoom(RoomName, mapID, cycleMode, isPrivate, VIPMap, requiresLabPass, client.getName());
      

      Main.getLobbyServer().getRoomRegistry().RegisterRoom(newRoom);
      newRoom.GetCR().registerClient(client);
      client.setRoom(newRoom);
      client.setLobbyStatus(Boolean.valueOf(false));
      Main.getLobbyServer().BroadcastPacket(StickPacketMaker.Disconnected(client.getUID()));
      client.setRequiresUpdate(Boolean.valueOf(true));
      client.write(StickPacketMaker.getNewPlayerUID(client.getUID()));

    }
    catch (Exception e)
    {
      System.out.println("Exception parsing create room packet. Packet: " + Packet);
      e.printStackTrace();
    }
  }
}