/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.Class
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.net.DatagramPacket
 *  java.net.DatagramSocket
 *  java.net.InetAddress
 *  java.net.UnknownHostException
 *  java.nio.Buffer
 *  java.nio.ByteBuffer
 */
package com.xinli.portalclient.util;

import com.google.code.microlog4android.Logger;
import com.google.code.microlog4android.LoggerFactory;
import com.xinli.portalclient.util.ThreeDes;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.Buffer;
import java.nio.ByteBuffer;

public class Sim_NetKeeperClient {
    private static final int TIMEOUT = 3000;
    private static final int dataType = 8;
    private static String encryKey;
    private static String key;
    private static final int localPort = 3311;
    private static final String serverHost = "222.177.26.12";
    private static final int serverPort = 443;
    private final transient Logger logger;
    private DatagramSocket socket;

    static {
        key = "";
        encryKey = "XINLIAPSECRET01234567891";
    }

    public Sim_NetKeeperClient() throws Exception {
        this.logger = LoggerFactory.getLogger(this.getClass());
        this.socket = null;
        if (this.socket == null) {
            this.socket = new DatagramSocket(3311);
        }
    }

    public void acceptHeartResponse() {
        byte[] arrby = new byte[200];
        try {
            DatagramPacket datagramPacket = new DatagramPacket(arrby, arrby.length);
            this.setSoTimeout(3000);
            this.logger.info("\u9632\u4ee3\u7406\u5fc3\u8df3\u51c6\u5907\u63a5\u53d7\u8fd4\u56de\u6570\u636e");
            this.socket.receive(datagramPacket);
            this.logger.info("\u9632\u4ee3\u7406\u5fc3\u8df3\u51c6\u5907\u8fd4\u56de\u6570\u636e\u6210\u529f");
            ByteBuffer byteBuffer = ByteBuffer.wrap((byte[])datagramPacket.getData());
            byte[] arrby2 = new byte[4];
            byteBuffer.get(arrby2);
            byte by = byteBuffer.get();
            byte[] arrby3 = new byte[byteBuffer.getInt()];
            byteBuffer.get(arrby3);
            byte[] arrby4 = ThreeDes.decryptMode(arrby3, encryKey);
            key = new String(arrby4);
            this.logger.warn("\u534f\u8bae" + new String(arrby2) + " \u62a5\u6587\u7c7b\u578b" + by + " \u89e3\u5bc6\u8fc7\u540e\u7684\u6570\u636e\u662f:" + new String(arrby4));
            return;
        }
        catch (Exception var3_8) {
            this.logger.error("\u9632\u4ee3\u7406\u5fc3\u8df3\u63a5\u6536\u5f02\u5e38:" + var3_8.getMessage());
            if (this.logger.isDebugEnabled()) {
                this.logger.info("\u670d\u52a1\u5668\u63a5\u6536\u62a5\u6587\u51fa\u9519");
            }
            var3_8.printStackTrace();
            return;
        }
    }

    public final void close() {
        try {
            this.socket.close();
            return;
        }
        catch (Exception var1_1) {
            var1_1.printStackTrace();
            return;
        }
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public DatagramPacket createPackage(String string2, int n) {
        InetAddress inetAddress;
        byte[] arrby = ThreeDes.encryptMode(string2.getBytes(), encryKey);
        ByteBuffer byteBuffer = ByteBuffer.allocate((int)(9 + arrby.length));
        byteBuffer.put("HR10".getBytes());
        byteBuffer.put((byte)n);
        byteBuffer.putInt(arrby.length);
        byteBuffer.put(arrby);
        byteBuffer.flip();
        byte[] arrby2 = byteBuffer.array();
        try {
            InetAddress inetAddress2;
            inetAddress = inetAddress2 = InetAddress.getByName((String)"222.177.26.12");
        }
        catch (UnknownHostException var11_8) {
            this.logger.error("\u4e0d\u80fd\u8bc6\u522b\u7684\u8fdc\u7a0b\u4e3b\u673a:222.177.26.12");
            inetAddress = null;
            return new DatagramPacket(arrby2, arrby2.length, inetAddress, 443);
        }
        do {
            return new DatagramPacket(arrby2, arrby2.length, inetAddress, 443);
            break;
        } while (true);
    }

    public final int getSoTimeout() throws Exception {
        return this.socket.getSoTimeout();
    }

    public final DatagramSocket getSocket() {
        return this.socket;
    }

    public void sendDataPackage(String string2, String string3, String string4) throws Exception {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("TYPE=").append("HEARTBEAT").append("&").append("USER_NAME=").append(string2).append("&").append("IP=").append(string3).append("&").append("VERSION_NUMBER=").append(string4).append("&").append("KEY=").append(key);
        DatagramPacket datagramPacket = this.createPackage(stringBuffer.toString(), 8);
        try {
            this.socket.send(datagramPacket);
            this.logger.debug("\u62a5\u65878\u53d1\u9001\u6210\u529f");
            return;
        }
        catch (Exception var7_6) {
            this.logger.error("\u53d1\u9001\u5fc3\u8df3\u5931\u8d25" + var7_6.getMessage());
            throw new Exception(var7_6.getMessage());
        }
    }

    public void sendHeart(String string2, String string3, String string4) throws Exception {
        this.sendDataPackage(string2, string3, string4);
        this.acceptHeartResponse();
        try {
            this.socket.close();
            return;
        }
        catch (Exception var4_4) {
            var4_4.printStackTrace();
            return;
        }
    }

    public final void setSoTimeout(int n) throws Exception {
        this.socket.setSoTimeout(n);
    }
}

