Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
16 kB
2
Indexable
Never
package ballistickemu.Types;

import ballistickemu.Lobby.LobbyServer;
import ballistickemu.Main;
import ballistickemu.Tools.DatabaseTools;
import ballistickemu.Tools.QuickplayTool;
import ballistickemu.Tools.StickPacketMaker;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import org.apache.mina.core.session.IoSession;

public class StickClient
{
  public static final String CLIENT_KEY = "CLIENT";
  private IoSession session;
  private String UID;
  private int kills;
  private int deaths;
  private int wins;
  private int losses;
  private int rounds;
  private int passExpiry;
  private int ticket;
  private int cash;
  private int game_wins;
  private int game_kills;
  private int game_deaths;
  private int user_level;
  private int dbID;
  private String name;
  private Boolean IsAtLobby;
  private Boolean IsReal;
  private Boolean HasPass;
  private StickColour colour;
  private StickRoom Room;
  private Boolean IsMod;
  private Boolean IsMuted;
  private Boolean IsBlended;
  private Boolean IsQuickplayChar;
  private Boolean IsRequiresUpdate;
  private LinkedHashMap<Integer, StickItem> Inventory;
  public ReentrantReadWriteLock InventoryLock = new ReentrantReadWriteLock(true);
  
  
  public StickClient(IoSession paramIoSession, String paramString)
  {
    this.session = paramIoSession;
    this.UID = paramString;
    this.IsAtLobby = Boolean.valueOf(true);
    this.IsReal = Boolean.valueOf(false);
    this.IsMod = Boolean.valueOf(false);
    this.IsBlended = Boolean.valueOf(false);
    this.IsMuted = Boolean.valueOf(false);
    this.IsQuickplayChar = Boolean.valueOf(false);
    this.IsRequiresUpdate = Boolean.valueOf(true);
    this.game_wins = 0;
    this.game_deaths = 0;
    this.game_kills = 0;
    this.colour = new StickColour(0, 0, 0, 0, 0, 0);
    this.Inventory = new LinkedHashMap();
    this.dbID = -1;
  }
  

  public StickClient() {}
  


  public void setUID(String paramString)
  {
    this.UID = paramString;
  }
  
  public void setDbID(int paramInt)
  {
    this.dbID = paramInt;
  }
  
  public void setUserLevel(int paramInt)
  {
    this.user_level = paramInt;
  }
  
  public void setRequiresUpdate(Boolean paramBoolean) {
    this.IsRequiresUpdate = paramBoolean;
  }
  


  public void setName(String paramString)
  {
    this.name = paramString;
  }
  
  public void setDeaths(int paramInt)
  {
    this.deaths = paramInt;
  }
  
  public void setWins(int paramInt)
  {
    this.wins = paramInt;
  }
  
  public void setLosses(int paramInt)
  {
    this.losses = paramInt;
  }
  
  public void setPassExpiry(int paramInt)
  {
    this.passExpiry = paramInt;
  }
  
  public void setRounds(int paramInt)
  {
    this.rounds = paramInt;
  }
  
  public void setTicket(int paramInt)
  {
    this.ticket = paramInt;
  }
  
  public void setCash(int paramInt)
  {
    this.cash = paramInt;
  }
  
  public void setPass(Boolean paramBoolean)
  {
    this.HasPass = paramBoolean;
  }
  


  public void setModStatus(Boolean paramBoolean)
  {
    this.IsMod = paramBoolean;
  }
  
  public void setBlendedStatus(Boolean paramBoolean) {
    this.IsBlended = paramBoolean;
  }
  



  public void setColour1(String paramString)
  {
    this.colour.setColour1FromString(paramString);
  }
  
  public void setColour2(String paramString)
  {
    this.colour.setColour2FromString(paramString);
  }
  

  public void setKills(int paramInt)
  {
    this.kills = paramInt;
  }


  public void setGameKills(int paramInt)
  {
    this.game_kills = paramInt;
  }
  

  public void setGameDeaths(int paramInt)
  {
    this.game_deaths = paramInt;
  }
  

  public void setLobbyStatus(Boolean paramBoolean)
  {
    this.IsAtLobby = paramBoolean;
  }
  

  public void setGameWins(int paramInt)
  {
    this.game_wins = (paramInt % 9);
  }
  
  public void incrementGameWins()
  {
    this.game_wins = ((this.game_wins + 1) % 9);
    if (this.game_wins > 9) {
      this.game_wins -= 10;
    }
  }
  
  public void setIsReal(Boolean paramBoolean)
  {
    this.IsReal = paramBoolean;
  }
  
  public void setMuteStatus(Boolean paramBoolean)
  {
    this.IsMuted = paramBoolean;
  }
  

  public void setRoom(StickRoom paramStickRoom)
  {
    this.Room = paramStickRoom;
  }
  
  public void setQuickplayStatus(Boolean paramBoolean)
  {
    this.IsQuickplayChar = paramBoolean;
  }
  




  public String getUID()
  {
    return this.UID;
  }
  




  public String getName()
  {
    return this.name;
  }
  




  public String getColour()
  {
    return this.colour.getColour1AsString();
  }
  
  public String getColour2()
  {
    return this.colour.getColour2AsString();
  }
  



  public int getKills()
  {
    return this.kills;
  }
  




  public int getGameKills()
  {
    return this.game_kills;
  }
  




  public int getGameDeaths()
  {
    return this.game_deaths;
  }
  




  public Boolean getLobbyStatus()
  {
    return this.IsAtLobby;
  }
  
  public Boolean getRequiresUpdate()
  {
    return this.IsRequiresUpdate;
  }
  




  public IoSession getIoSession()
  {
    return this.session;
  }
  
  public Boolean getReal()
  {
    return this.IsReal;
  }
  
  public Boolean getModStatus()
  {
    return this.IsMod;
  }
  
  public Boolean isBlended() {
    return this.IsMod;
  }
  
  public Boolean getPass()
  {
    return this.HasPass;
  }
  
  public Boolean getMuteStatus()
  {
    return this.IsMuted;
  }
  
  public Boolean getQuickplayStatus()
  {
    return this.IsQuickplayChar;
  }
  

  public StickRoom getRoom()
  {
    return this.Room;
  }
  
  public int getDeaths()
  {
    return this.deaths;
  }
  
  public int getWins()
  {
    return this.wins;
  }
  
  public int getLosses()
  {
    return this.losses;
  }
  
  public int getPassExpiry()
  {
    return this.passExpiry;
  }
  
  public int getRounds()
  {
    return this.rounds;
  }
  
  public int getGameWins() {
    return this.game_wins;
  }
  
  public int getTicket()
  {
    return this.ticket;
  }
  
  public int getCash()
  {
    return this.cash;
  }
  
  public int getUserLevel()
  {
    if ((this.IsMod.booleanValue()) && (this.IsBlended.booleanValue()))
      return 0;
    return this.user_level;
  }
  
  public int getDbID()
  {
    return this.dbID;
  }
  
  public LinkedHashMap<Integer, StickItem> getInventory()
  {
    return this.Inventory;
  }
  



  public void write(StickPacket paramStickPacket)
  {
    if (paramStickPacket.getString().length() < 1) {
      return;
    }
    try {
      this.session.write(paramStickPacket.getString().substring(0, paramStickPacket.getString().length() - 1));
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      if (getLobbyStatus().booleanValue())
      {
        Main.getLobbyServer().getClientRegistry().deregisterClient(this);
      }
      else if (this.Room != null)
      {
        this.Room.GetCR().deregisterClient(this);
      }
    }
  }
  

  public void writePolicyFile()
  {
    if (this.session.isConnected()) {
      this.session.write("<cross-domain-policy><allow-access-from domain=\"" + Main.IP + "\" to-ports=\"3724,47624,1138,1139,443,110,80\" /></cross-domain-policy>");
    }
  }
  
  public void writeMessage(String paramString) {
    write(StickPacketMaker.getMessagePacket(paramString, this.UID));
  }
  
  public void writeCallbackMessage(String paramString)
  {
    write(StickPacketMaker.getCallbackPacket(paramString));
  }
  
  public void writeAnnounce(String paramString) {
    write(StickPacketMaker.getAnnouncePacket(paramString));
  }
  
  public void getPrize(String paramString) {
    write(StickPacketMaker.getPrize(paramString));
  }
  
  public void getMaps(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5) {
    write(StickPacketMaker.getMaps(paramString1, paramString2, paramString3, paramString4, paramString5));
  }
  
  public void getDLogin() {
    write(StickPacketMaker.getDLogin());
  }
  
  public void finalize()
    throws Throwable
  {
    super.finalize();
  }
  
    public void addItemToInventory(int paramInt, StickItem paramStickItem)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 4	ballistickemu/Types/StickClient:InventoryLock	Ljava/util/concurrent/locks/ReentrantReadWriteLock;
    //   4: invokevirtual 69	java/util/concurrent/locks/ReentrantReadWriteLock:writeLock	()Ljava/util/concurrent/locks/ReentrantReadWriteLock$WriteLock;
    //   7: invokevirtual 70	java/util/concurrent/locks/ReentrantReadWriteLock$WriteLock:lock	()V
    //   10: aload_0
    //   11: getfield 23	ballistickemu/Types/StickClient:Inventory	Ljava/util/LinkedHashMap;
    //   14: iload_1
    //   15: invokestatic 71	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   18: aload_2
    //   19: invokevirtual 72	java/util/LinkedHashMap:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   22: pop
    //   23: aload_0
    //   24: getfield 4	ballistickemu/Types/StickClient:InventoryLock	Ljava/util/concurrent/locks/ReentrantReadWriteLock;
    //   27: invokevirtual 69	java/util/concurrent/locks/ReentrantReadWriteLock:writeLock	()Ljava/util/concurrent/locks/ReentrantReadWriteLock$WriteLock;
    //   30: invokevirtual 73	java/util/concurrent/locks/ReentrantReadWriteLock$WriteLock:unlock	()V
    //   33: goto +16 -> 49
    //   36: astore_3
    //   37: aload_0
    //   38: getfield 4	ballistickemu/Types/StickClient:InventoryLock	Ljava/util/concurrent/locks/ReentrantReadWriteLock;
    //   41: invokevirtual 69	java/util/concurrent/locks/ReentrantReadWriteLock:writeLock	()Ljava/util/concurrent/locks/ReentrantReadWriteLock$WriteLock;
    //   44: invokevirtual 73	java/util/concurrent/locks/ReentrantReadWriteLock$WriteLock:unlock	()V
    //   47: aload_3
    //   48: athrow
    //   49: return
    // Line number table:
    //   Java source line #503	-> byte code offset #0
    //   Java source line #505	-> byte code offset #10
    //   Java source line #507	-> byte code offset #23
    //   Java source line #508	-> byte code offset #33
    //   Java source line #507	-> byte code offset #36
    //   Java source line #509	-> byte code offset #49
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	50	0	this	StickClient
    //   0	50	1	paramInt	int
    //   0	50	2	paramStickItem	StickItem
    //   36	12	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   10	23	36	finally
  }
  
  public StickItem getItemByID(int paramInt)
  {
    this.InventoryLock.readLock().lock();
    try { StickItem localStickItem;
      if (!this.Inventory.containsKey(Integer.valueOf(paramInt))) {
        return null;
      }
      return (StickItem)this.Inventory.get(Integer.valueOf(paramInt));
    } finally {
      this.InventoryLock.readLock().unlock();
    }
  }
  
  public void setSelectedItem(int paramInt1, int paramInt2)
  {
    this.InventoryLock.readLock().lock();
    try
    {
      for (StickItem localStickItem : this.Inventory.values())
      {
        if (localStickItem.getitemType() == paramInt1) {
          localStickItem.setSelected(Boolean.valueOf(false));
        }
        if (localStickItem.getItemDBID() == paramInt2) {
          localStickItem.setSelected(Boolean.valueOf(true));
        }
      }
    } finally {
      this.InventoryLock.readLock().unlock();
    }
  }
  
  public StickItem getFirstSpinner()
  {
    this.InventoryLock.readLock().lock();
    try
    {
      for (StickItem localStickItem1 : this.Inventory.values())
      {
        if (localStickItem1.getitemType() == 1)
          return localStickItem1;
      }
    } finally {
      this.InventoryLock.readLock().unlock();
    }
    return null;
  }
  
  public StickItem getFirstPet()
  {
    this.InventoryLock.readLock().lock();
    try
    {
      for (StickItem localStickItem1 : this.Inventory.values())
      {
        if (localStickItem1.getitemType() == 2)
          return localStickItem1;
      }
    } finally {
      this.InventoryLock.readLock().unlock();
    }
    return null;
  }
  
  public StickItem getSelectedSpinner()
  {
    this.InventoryLock.readLock().lock();
    try
    {
      for (localObject1 = this.Inventory.values().iterator(); ((Iterator)localObject1).hasNext();) { StickItem localStickItem1 = (StickItem)((Iterator)localObject1).next();
        
        if ((localStickItem1.getitemType() == 1) && (localStickItem1.isSelected().booleanValue()))
          return localStickItem1;
      }
    } finally {
      this.InventoryLock.readLock().unlock();
    }
    Object localObject1 = getFirstSpinner();
    ((StickItem)localObject1).setSelected(Boolean.valueOf(true));
    setSelectedInDB((StickItem)localObject1);
    return (StickItem)localObject1;
  }
  
  public StickItem getSelectedPet()
  {
    this.InventoryLock.readLock().lock();
    try
    {
      for (localObject1 = this.Inventory.values().iterator(); ((Iterator)localObject1).hasNext();) { StickItem localStickItem1 = (StickItem)((Iterator)localObject1).next();
        
        if ((localStickItem1.getitemType() == 2) && (localStickItem1.isSelected().booleanValue()))
          return localStickItem1;
      }
    } finally {
      this.InventoryLock.readLock().unlock();
    }
    Object localObject1 = getFirstPet();
    ((StickItem)localObject1).setSelected(Boolean.valueOf(true));
    setSelectedInDB((StickItem)localObject1);
    return (StickItem)localObject1;
  }
  
  public String getFormattedInventoryData()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    this.InventoryLock.readLock().lock();
    int i = 0;
    try
    {
      for (StickItem localStickItem : this.Inventory.values())
      {
        if (localStickItem.isSelected().booleanValue())
          i = 1;
        localStringBuilder.append(localStickItem.getItemID());
        localStringBuilder.append(i);
        localStringBuilder.append(localStickItem.getColour().getColour1AsString());
        localStringBuilder.append(localStickItem.getColour().getColour2AsString());
        localStringBuilder.append(localStickItem.getItemDBID());
        localStringBuilder.append(";");
        i = 0;
      }
    }
    finally
    {
      this.InventoryLock.readLock().unlock();
    }
    return localStringBuilder.toString();
  }
  
  public StickColour getStickColour()
  {
    return this.colour;
  }
  
  private void setSelectedInDB(StickItem paramStickItem)
  {
    try
    {
      if (paramStickItem != null)
      {
        PreparedStatement localPreparedStatement = DatabaseTools.getDbConnection().prepareStatement("UPDATE `inventory` SET `selected` = 0 WHERE `itemtype` = ? AND `userid` = ?");
        localPreparedStatement.setInt(1, paramStickItem.getitemType());
        localPreparedStatement.setInt(2, this.dbID);
        localPreparedStatement.executeUpdate();
        localPreparedStatement = DatabaseTools.getDbConnection().prepareStatement("UPDATE `inventory` SET `selected` = 1 WHERE `id` = ? AND `userid` = ?");
        localPreparedStatement.setInt(1, paramStickItem.getItemDBID());
        localPreparedStatement.setInt(2, this.dbID);
        localPreparedStatement.executeUpdate();
      }
    }
    catch (Exception localException) {
      localException.printStackTrace();
    }
  }
  
  public void setUpAsQuickplay()
  {
    this.IsQuickplayChar = Boolean.valueOf(true);
    this.HasPass = Boolean.valueOf(false);
    this.name = QuickplayTool.getRandomName();
    this.Inventory = QuickplayTool.getRandomInventory();
  }
}