Untitled

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

import ballistickemu.Lobby.LobbyServer;
import ballistickemu.Main;
import ballistickemu.Tools.DatabaseTools;
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 java.io.PrintStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedHashMap;
import org.apache.mina.core.session.IoSession;


public class LoginHandler
{
  public static void HandlePacket(StickClient paramStickClient, String paramString)
  {
    String[] arrayOfString = paramString.replaceAll("\000", "").substring(2).split(";");
    if (arrayOfString[0].length() > 20)
    {
      paramStickClient.getIoSession().close(true);
      return;
    }
    String str1 = "";
    try
    {
      str1 = arrayOfString[1];
    } catch (Exception localException1) {
      localException1.printStackTrace();
    }
    try
    {
      if ((DatabaseTools.getDbConnection().isClosed()) || (DatabaseTools.getDbConnection() == null)) {
        DatabaseTools.dbConnect();
      }
      PreparedStatement localPreparedStatement1 = DatabaseTools.getDbConnection().prepareStatement("SELECT * FROM `users` WHERE `USERname` = ? AND `USERpass` = ?");
      localPreparedStatement1.setString(1, arrayOfString[0]);
      localPreparedStatement1.setString(2, str1);
      
      ResultSet localResultSet = localPreparedStatement1.executeQuery();
      localResultSet.last();
      int i = localResultSet.getRow();
      
      if (i < 1)
      {
        paramStickClient.write(StickPacketMaker.getLoginFailed());
        return;
      }

      String str2 = StringTool.PadStringLeft(arrayOfString[0], "#", 20);
      String str3 = StringTool.PadStringLeft(String.valueOf(localResultSet.getInt("red")), "0", 3);
      String str4 = StringTool.PadStringLeft(String.valueOf(localResultSet.getInt("green")), "0", 3);
      String str5 = StringTool.PadStringLeft(String.valueOf(localResultSet.getInt("blue")), "0", 3);
      
      String str6 = str3 + str4 + str5;
      int j = localResultSet.getInt("kills");
      int k = localResultSet.getInt("deaths");
      int m = localResultSet.getInt("wins");
      int n = localResultSet.getInt("losses");
      int i1 = localResultSet.getInt("rounds");
      int i2 = localResultSet.getInt("passexpiry");
      int i3 = localResultSet.getInt("cash");
      int i4 = localResultSet.getInt("ticket");
      int i5 = localResultSet.getInt("labpass");
      int i6 = localResultSet.getInt("user_level");
      int i7 = localResultSet.getInt("UID");
      

      paramStickClient.setName(arrayOfString[0]);
      paramStickClient.setColour1(str6);
      paramStickClient.setColour2(str6);
      paramStickClient.setKills(j);
      paramStickClient.setDeaths(k);
      paramStickClient.setWins(m);
      paramStickClient.setLosses(n);
      paramStickClient.setRounds(i1);
      paramStickClient.setPassExpiry(i2);
      paramStickClient.setCash(i3);
      paramStickClient.setTicket(i4);
      paramStickClient.setPass(Boolean.valueOf(i5 == 1));
      paramStickClient.setModStatus(Boolean.valueOf(i6 > 0));
      paramStickClient.setUserLevel(i6);
      paramStickClient.setDbID(i7);
      
      Boolean localBoolean1 = Boolean.valueOf(false);
      Boolean localBoolean2 = Boolean.valueOf(false);
      

      if (localResultSet.getInt("ban") == 1)
      {
        paramStickClient.write(StickPacketMaker.getErrorPacket("1"));
        return;
      }
      while (!localBoolean1.booleanValue())
      {
        localObject1 = DatabaseTools.getDbConnection().prepareStatement("SELECT * FROM `inventory` WHERE `userid` = ?");
        ((PreparedStatement)localObject1).setInt(1, i7);
        
        localResultSet = ((PreparedStatement)localObject1).executeQuery();
        
        localResultSet.last();
        if (localResultSet.getRow() > 1)
          localBoolean2 = Boolean.valueOf(false);
        PreparedStatement localPreparedStatement2;
        Object localObject2; Object localObject3; if (localResultSet.getRow() < 2)
        {
          localPreparedStatement2 = DatabaseTools.getDbConnection().prepareStatement("DELETE FROM `inventory` where `userid` = ?");
          localPreparedStatement2.setInt(1, i7);
          localPreparedStatement2.executeUpdate();
          localObject2 = DatabaseTools.getDbConnection().prepareStatement("INSERT INTO `inventory` (`userid`, `itemid`, `itemtype`, `red1`, `green1`, `blue1`, `red2`, `green2`, `blue2`, `selected`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
          
          ((PreparedStatement)localObject2).setInt(1, paramStickClient.getDbID());
          ((PreparedStatement)localObject2).setInt(2, 100);
          ((PreparedStatement)localObject2).setInt(3, 1);
          ((PreparedStatement)localObject2).setInt(4, paramStickClient.getStickColour().getRed1());
          ((PreparedStatement)localObject2).setInt(5, paramStickClient.getStickColour().getGreen1());
          ((PreparedStatement)localObject2).setInt(6, paramStickClient.getStickColour().getBlue1());
          ((PreparedStatement)localObject2).setInt(7, paramStickClient.getStickColour().getRed2());
          ((PreparedStatement)localObject2).setInt(8, paramStickClient.getStickColour().getGreen2());
          ((PreparedStatement)localObject2).setInt(9, paramStickClient.getStickColour().getBlue2());
          ((PreparedStatement)localObject2).setInt(10, 1);
          ((PreparedStatement)localObject2).executeUpdate();
          ((PreparedStatement)localObject2).close();
          
          localObject3 = DatabaseTools.getDbConnection().prepareStatement("INSERT INTO `inventory` (`userid`, `itemid`, `itemtype`, `red1`, `green1`, `blue1`, `red2`, `green2`, `blue2`, `selected`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
          
          ((PreparedStatement)localObject3).setInt(1, paramStickClient.getDbID());
          ((PreparedStatement)localObject3).setInt(2, 200);
          ((PreparedStatement)localObject3).setInt(3, 2);
          ((PreparedStatement)localObject3).setInt(4, 0);
          ((PreparedStatement)localObject3).setInt(5, 0);
          ((PreparedStatement)localObject3).setInt(6, 0);
          ((PreparedStatement)localObject3).setInt(7, 0);
          ((PreparedStatement)localObject3).setInt(8, 0);
          ((PreparedStatement)localObject3).setInt(9, 0);
          ((PreparedStatement)localObject3).setInt(10, 1);
          ((PreparedStatement)localObject3).executeUpdate();
          ((PreparedStatement)localObject3).close();
          localBoolean2 = Boolean.valueOf(true);
        }
        
        if (!localBoolean2.booleanValue())
        {
          localPreparedStatement2 = DatabaseTools.getDbConnection().prepareStatement("SELECT * FROM `inventory` WHERE `userid` = ?");
          localPreparedStatement2.setInt(1, i7);
          localObject2 = localPreparedStatement2.executeQuery();
          while (((ResultSet)localObject2).next())
          {

            localObject3 = new StickColour(((ResultSet)localObject2).getInt("red1"), ((ResultSet)localObject2).getInt("green1"), ((ResultSet)localObject2).getInt("blue1"), ((ResultSet)localObject2).getInt("red2"), ((ResultSet)localObject2).getInt("green2"), ((ResultSet)localObject2).getInt("blue2"));
            int i8 = ((ResultSet)localObject2).getInt("id");
            int i9 = ((ResultSet)localObject2).getInt("itemid");
            
            paramStickClient.getInventory().put(Integer.valueOf(i8), new StickItem(i9, i8, i7, ((ResultSet)localObject2).getInt("itemtype"), Boolean.valueOf(((ResultSet)localObject2).getInt("selected") == 1), (StickColour)localObject3));
          }
          

          localBoolean1 = Boolean.valueOf(true);
          ((ResultSet)localObject2).close();
          localPreparedStatement2.close();
        }
        localResultSet.close();
        ((PreparedStatement)localObject1).close();
      }

      str6 = paramStickClient.getSelectedSpinner().getColour().getColour1AsString();
      Object localObject1 = paramStickClient.getSelectedSpinner().getColour().getColour2AsString();
      paramStickClient.write(StickPacketMaker.getLoginSuccess(paramStickClient.getUID(), str2, str6, (String)localObject1, j, k, m, n, i1, i5, i2, i4, i3, i6));
      Main.getLobbyServer().getClientRegistry().registerClient(paramStickClient);
      paramStickClient.setIsReal(Boolean.valueOf(true));
    }
    catch (Exception localException2)
    {
      System.out.println("Exception at login: + " + localException2.toString());
      localException2.printStackTrace();
    }
  }
}