Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.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.StickColour;
import ballistickemu.Types.StickItem;
import ballistickemu.Types.StickRoom;
import ballistickemu.Types.StickRoomRegistry;
import java.io.PrintStream;
import org.apache.mina.core.session.IoSession;


public class NewClientHandler
{
  public static void HandlePacket(StickClient client, String Packet)
  {
    if (Packet.substring(0, 3).equalsIgnoreCase("03_"))
    {
      if ((client.getQuickplayStatus().booleanValue()) || (client.getName() == null))
      {
        client.getIoSession().close(true);
        return;
      }
      
      if (client.getRequiresUpdate().booleanValue())
      {
        if (client.getRoom() != null)
        {
          client.getRoom().GetCR().deregisterClient(client);
          client.setRoom(null);
          client.setLobbyStatus(Boolean.valueOf(true));
        }
        
        Main.getLobbyServer().BroadcastPacket(StickPacketMaker.getNewPlayerUID(client.getUID()));
        client.write(StickPacketMaker.getUserList(Main.getLobbyServer().getClientRegistry(), client.getUID(), Boolean.valueOf(true), client));
        Main.getLobbyServer().BroadcastPacket(StickPacketMaker.getClientInfo(client.getUID(), client.getName(), client.getSelectedSpinner().getColour().getColour1AsString(), client.getKills(), client.getDeaths(), client.getWins(), client.getLosses(), client.getRounds(), client.getPass().booleanValue() ? 1 : 0, client.getUserLevel()), Boolean.valueOf(true), client.getUID());
        

        client.setRequiresUpdate(Boolean.valueOf(false));
      }
      else {
        int pass = 0;
        if (client.getPass().booleanValue())
          pass = 1;
        Main.getLobbyServer().BroadcastPacket(StickPacketMaker.getClientInfo(client.getUID(), client.getName(), client.getSelectedSpinner().getColour().getColour1AsString(), client.getKills(), client.getDeaths(), client.getWins(), client.getLosses(), client.getRounds(), pass, client.getUserLevel()));
        
        client.write(StickPacketMaker.getLoginFailed());
      }
      client.setLobbyStatus(Boolean.valueOf(true));
    }
    else
    {
      client.setIsReal(Boolean.valueOf(true));
      if (client.getName() == null)
      {
        client.setUpAsQuickplay();
      }
      else
      {
        client.setQuickplayStatus(Boolean.valueOf(false));
      }
      
      String RoomName = Packet.substring(2, Packet.length() - 1);
      try
      {
        StickRoom Room = Main.getLobbyServer().getRoomRegistry().GetRoomFromName(RoomName);
        client.setLobbyStatus(Boolean.valueOf(false));
        client.setRequiresUpdate(Boolean.valueOf(true));
        Room.GetCR().registerClient(client);
        client.setRoom(Room);
        if (!client.getQuickplayStatus().booleanValue())
          Main.getLobbyServer().BroadcastPacket(StickPacketMaker.Disconnected(client.getUID()));
        Room.BroadcastToRoom(StickPacketMaker.getNewPlayerUID(client.getUID()));
        


        String petID = StringTool.PadStringLeft(String.valueOf(client.getSelectedPet().getItemID() - 200), "0", 2);
        String petColour1 = client.getSelectedPet().getColour().getColour1AsString();
        String petColour2 = client.getSelectedPet().getColour().getColour2AsString();
        
        String spinnerID = StringTool.PadStringLeft(String.valueOf(client.getSelectedSpinner().getItemID() - 100), "0", 2);
        String spinnerColour1 = client.getSelectedSpinner().getColour().getColour1AsString();
        String spinnerColour2 = client.getSelectedSpinner().getColour().getColour2AsString();
        
        Room.BroadcastToRoom(StickPacketMaker.getUserDataGame(client.getUID(), client.getGameWins(), client.getGameKills(), client.getGameDeaths(), StringTool.PadStringLeft(client.getName(), "#", 20), spinnerID, spinnerColour1, spinnerColour2, client.getKills(), petID, petColour1, petColour2));
        

        client.write(StickPacketMaker.getUserListGame(Room.GetCR(), client.getUID(), Boolean.valueOf(false), client));
      }
      catch (Exception e)
      {
        client.setLobbyStatus(Boolean.valueOf(true));
        Main.getLobbyServer().getRoomRegistry().GetRoomFromName(RoomName).GetCR().deregisterClient(client);
        System.out.println("Exception when parsing join room packet: " + e.toString());
        e.printStackTrace();
      }
    }
  }
}