Example usage for java.nio ByteBuffer getShort

List of usage examples for java.nio ByteBuffer getShort

Introduction

In this page you can find the example usage for java.nio ByteBuffer getShort.

Prototype

public abstract short getShort();

Source Link

Document

Returns the short at the current position and increases the position by 2.

Usage

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private ArrayList<Pair<Integer, Object>> decodeDict(ByteBuffer buf) {
    ArrayList<Pair<Integer, Object>> dict = new ArrayList<>();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    byte dictSize = buf.get();
    while (dictSize-- > 0) {
        Integer key = buf.getInt();
        byte type = buf.get();
        short length = buf.getShort();
        switch (type) {
        case TYPE_INT:
        case TYPE_UINT:
            if (length == 1) {
                dict.add(new Pair<Integer, Object>(key, buf.get()));
            } else if (length == 2) {
                dict.add(new Pair<Integer, Object>(key, buf.getShort()));
            } else {
                dict.add(new Pair<Integer, Object>(key, buf.getInt()));
            }//  ww  w .jav  a 2  s  . com
            break;
        case TYPE_CSTRING:
        case TYPE_BYTEARRAY:
            byte[] bytes = new byte[length];
            buf.get(bytes);
            if (type == TYPE_BYTEARRAY) {
                dict.add(new Pair<Integer, Object>(key, bytes));
            } else {
                dict.add(new Pair<Integer, Object>(key, new String(bytes)));
            }
            break;
        default:
        }
    }
    return dict;
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private GBDeviceEvent decodeBlobDb(ByteBuffer buf) {
    final String ENDPOINT_NAME = "BLOBDB";
    final String statusString[] = { "unknown", "success", "general failure", "invalid operation",
            "invalid database id", "invalid data", "key does not exist", "database full", "data stale", };
    buf.order(ByteOrder.LITTLE_ENDIAN);
    short token = buf.getShort();
    byte status = buf.get();

    if (status >= 0 && status < statusString.length) {
        LOG.info(ENDPOINT_NAME + ": " + statusString[status] + " (token " + (token & 0xffff) + ")");
    } else {//from  w w  w. j a va2  s  . c om
        LOG.warn(ENDPOINT_NAME + ": unknown status " + status + " (token " + (token & 0xffff) + ")");
    }
    return null;
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
    ByteBuffer buf = ByteBuffer.wrap(responseData);
    buf.order(ByteOrder.BIG_ENDIAN);
    short length = buf.getShort();
    short endpoint = buf.getShort();
    GBDeviceEvent devEvts[] = null;/*ww  w .j a v a 2 s  . co  m*/
    byte pebbleCmd;
    switch (endpoint) {
    case ENDPOINT_MUSICCONTROL:
        pebbleCmd = buf.get();
        GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl();
        switch (pebbleCmd) {
        case MUSICCONTROL_NEXT:
            musicCmd.event = GBDeviceEventMusicControl.Event.NEXT;
            break;
        case MUSICCONTROL_PREVIOUS:
            musicCmd.event = GBDeviceEventMusicControl.Event.PREVIOUS;
            break;
        case MUSICCONTROL_PLAY:
            musicCmd.event = GBDeviceEventMusicControl.Event.PLAY;
            break;
        case MUSICCONTROL_PAUSE:
            musicCmd.event = GBDeviceEventMusicControl.Event.PAUSE;
            break;
        case MUSICCONTROL_PLAYPAUSE:
            musicCmd.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
            break;
        case MUSICCONTROL_VOLUMEUP:
            musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
            break;
        case MUSICCONTROL_VOLUMEDOWN:
            musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
            break;
        default:
            break;
        }
        devEvts = new GBDeviceEvent[] { musicCmd };
        break;
    case ENDPOINT_PHONECONTROL:
        pebbleCmd = buf.get();
        GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
        switch (pebbleCmd) {
        case PHONECONTROL_HANGUP:
            callCmd.event = GBDeviceEventCallControl.Event.END;
            break;
        default:
            LOG.info("Unknown PHONECONTROL event" + pebbleCmd);
            break;
        }
        devEvts = new GBDeviceEvent[] { callCmd };
        break;
    case ENDPOINT_FIRMWAREVERSION:
        pebbleCmd = buf.get();
        GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();

        buf.getInt(); // skip
        versionCmd.fwVersion = getFixedString(buf, 32);

        mFwMajor = versionCmd.fwVersion.charAt(1) - 48;
        LOG.info("Pebble firmware major detected as " + mFwMajor);

        byte[] tmp = new byte[9];
        buf.get(tmp, 0, 9);
        int hwRev = buf.get() + 8;
        if (hwRev >= 0 && hwRev < hwRevisions.length) {
            versionCmd.hwVersion = hwRevisions[hwRev];
        }
        devEvts = new GBDeviceEvent[] { versionCmd };
        break;
    case ENDPOINT_APPMANAGER:
        pebbleCmd = buf.get();
        switch (pebbleCmd) {
        case APPMANAGER_GETAPPBANKSTATUS:
            GBDeviceEventAppInfo appInfoCmd = new GBDeviceEventAppInfo();
            int slotCount = buf.getInt();
            int slotsUsed = buf.getInt();
            appInfoCmd.apps = new GBDeviceApp[slotsUsed];
            boolean[] slotInUse = new boolean[slotCount];

            for (int i = 0; i < slotsUsed; i++) {
                int id = buf.getInt();
                int index = buf.getInt();
                slotInUse[index] = true;
                String appName = getFixedString(buf, 32);
                String appCreator = getFixedString(buf, 32);

                int flags = buf.getInt();

                GBDeviceApp.Type appType;
                if ((flags & 16) == 16) { // FIXME: verify this assumption
                    appType = GBDeviceApp.Type.APP_ACTIVITYTRACKER;
                } else if ((flags & 1) == 1) { // FIXME: verify this assumption
                    appType = GBDeviceApp.Type.WATCHFACE;
                } else {
                    appType = GBDeviceApp.Type.APP_GENERIC;
                }
                Short appVersion = buf.getShort();
                appInfoCmd.apps[i] = new GBDeviceApp(tmpUUIDS.get(i), appName, appCreator,
                        appVersion.toString(), appType);
            }
            for (int i = 0; i < slotCount; i++) {
                if (!slotInUse[i]) {
                    appInfoCmd.freeSlot = (byte) i;
                    LOG.info("found free slot " + i);
                    break;
                }
            }
            devEvts = new GBDeviceEvent[] { appInfoCmd };
            break;
        case APPMANAGER_GETUUIDS:
            GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
            sendBytes.encodedBytes = encodeSimpleMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS);
            devEvts = new GBDeviceEvent[] { sendBytes };
            tmpUUIDS.clear();
            slotsUsed = buf.getInt();
            for (int i = 0; i < slotsUsed; i++) {
                UUID uuid = getUUID(buf);
                LOG.info("found uuid: " + uuid);
                tmpUUIDS.add(uuid);
            }
            break;
        case APPMANAGER_REMOVEAPP:
            GBDeviceEventAppManagement deleteRes = new GBDeviceEventAppManagement();
            deleteRes.type = GBDeviceEventAppManagement.EventType.DELETE;

            int result = buf.getInt();
            switch (result) {
            case APPMANAGER_RES_SUCCESS:
                deleteRes.event = GBDeviceEventAppManagement.Event.SUCCESS;
                break;
            default:
                deleteRes.event = GBDeviceEventAppManagement.Event.FAILURE;
                break;
            }
            devEvts = new GBDeviceEvent[] { deleteRes };
            break;
        default:
            LOG.info("Unknown APPMANAGER event" + pebbleCmd);
            break;
        }
        break;
    case ENDPOINT_PUTBYTES:
        pebbleCmd = buf.get();
        GBDeviceEventAppManagement installRes = new GBDeviceEventAppManagement();
        installRes.type = GBDeviceEventAppManagement.EventType.INSTALL;
        switch (pebbleCmd) {
        case PUTBYTES_INIT:
            installRes.token = buf.getInt();
            installRes.event = GBDeviceEventAppManagement.Event.SUCCESS;
            break;
        default:
            installRes.token = buf.getInt();
            installRes.event = GBDeviceEventAppManagement.Event.FAILURE;
            break;
        }
        devEvts = new GBDeviceEvent[] { installRes };
        break;
    case ENDPOINT_APPLICATIONMESSAGE:
    case ENDPOINT_LAUNCHER:
        pebbleCmd = buf.get();
        last_id = buf.get();
        UUID uuid = getUUID(buf);

        switch (pebbleCmd) {
        case APPLICATIONMESSAGE_PUSH:
            LOG.info((endpoint == ENDPOINT_LAUNCHER ? "got LAUNCHER PUSH from UUID : "
                    : "got APPLICATIONMESSAGE PUSH from UUID : ") + uuid);
            AppMessageHandler handler = mAppMessageHandlers.get(uuid);
            if (handler != null) {
                if (handler.isEnabled()) {
                    if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
                        ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
                        devEvts = handler.handleMessage(dict);
                    } else {
                        currentRunningApp = uuid;
                        devEvts = handler.onAppStart();
                    }
                } else {
                    devEvts = new GBDeviceEvent[] { null };
                }
            } else {
                try {
                    if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
                        devEvts = decodeDictToJSONAppMessage(uuid, buf);
                    } else {
                        currentRunningApp = uuid;
                        GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
                        gbDeviceEventAppManagement.uuid = uuid;
                        gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
                        gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
                        devEvts = new GBDeviceEvent[] { gbDeviceEventAppManagement };
                    }
                } catch (JSONException e) {
                    LOG.error(e.getMessage());
                    return null;
                }
            }
            break;
        case APPLICATIONMESSAGE_ACK:
            LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  ACK");
            devEvts = new GBDeviceEvent[] { null };
            break;
        case APPLICATIONMESSAGE_NACK:
            LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  NACK");
            devEvts = new GBDeviceEvent[] { null };
            break;
        case APPLICATIONMESSAGE_REQUEST:
            LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  REQUEST");
            devEvts = new GBDeviceEvent[] { null };
            break;
        default:
            break;
        }
        break;
    case ENDPOINT_PHONEVERSION:
        pebbleCmd = buf.get();
        switch (pebbleCmd) {
        case PHONEVERSION_REQUEST:
            LOG.info("Pebble asked for Phone/App Version - repLYING!");
            GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
            sendBytes.encodedBytes = encodePhoneVersion(PHONEVERSION_REMOTE_OS_ANDROID);
            devEvts = new GBDeviceEvent[] { sendBytes };
            break;
        default:
            break;
        }
        break;
    case ENDPOINT_DATALOG:
        devEvts = decodeDatalog(buf, length);
        break;
    case ENDPOINT_SCREENSHOT:
        devEvts = new GBDeviceEvent[] { decodeScreenshot(buf, length) };
        break;
    case ENDPOINT_EXTENSIBLENOTIFS:
    case ENDPOINT_NOTIFICATIONACTION:
        devEvts = decodeAction(buf);
        break;
    case ENDPOINT_PING:
        devEvts = new GBDeviceEvent[] { decodePing(buf) };
        break;
    case ENDPOINT_APPFETCH:
        devEvts = new GBDeviceEvent[] { decodeAppFetch(buf) };
        break;
    case ENDPOINT_SYSTEMMESSAGE:
        devEvts = new GBDeviceEvent[] { decodeSystemMessage(buf) };
        break;
    case ENDPOINT_APPRUNSTATE:
        devEvts = decodeAppRunState(buf);
        break;
    case ENDPOINT_BLOBDB:
        devEvts = new GBDeviceEvent[] { decodeBlobDb(buf) };
        break;
    case ENDPOINT_APPREORDER:
        devEvts = new GBDeviceEvent[] { decodeAppReorder(buf) };
        break;
    case ENDPOINT_APPLOGS:
        decodeAppLogs(buf);
        break;
    //            case ENDPOINT_VOICECONTROL:
    //                devEvts = new GBDeviceEvent[]{decodeVoiceControl(buf)};
    //            case ENDPOINT_AUDIOSTREAM:
    //                LOG.debug(GB.hexdump(responseData, 0, responseData.length));
    //                break;
    default:
        break;
    }

    return devEvts;
}

From source file:au.org.ala.layers.intersect.Grid.java

public void replaceValues(Map<Integer, Integer> translation) {

    long length = ((long) nrows) * ((long) ncols);

    Integer minv = null;//from w  w w. j a v  a  2s  . com
    Integer maxv = null;
    for (Integer i : translation.values()) {
        if (minv == null || i < minv)
            minv = i;
        if (maxv == null || i > maxv)
            maxv = i;
    }

    RandomAccessFile afile = null;
    RandomAccessFile out = null;
    File f2 = new File(filename + ".GRI");
    File newGrid = new File(filename + ".gri.new");

    try { //read of random access file can throw an exception
        out = new RandomAccessFile(newGrid, "rw");

        if (!f2.exists()) {
            afile = new RandomAccessFile(filename + ".gri", "r");
        } else {
            afile = new RandomAccessFile(filename + ".GRI", "r");
        }

        byte[] b = new byte[65536];
        byte[] bout = new byte[65536];

        long i = 0;
        long max = 0;
        long len;
        float v;
        float ndv = (float) nodatavalue;

        while ((len = afile.read(b)) > 0) {
            ByteBuffer bb = ByteBuffer.wrap(b);
            ByteBuffer bbout = ByteBuffer.wrap(bout);

            if (byteorderLSB) {
                bb.order(ByteOrder.LITTLE_ENDIAN);
                bbout.order(ByteOrder.LITTLE_ENDIAN);
            }

            if (datatype.equalsIgnoreCase("UBYTE")) {
                throw new Exception("UBYTE translation not supported");
            } else if (datatype.equalsIgnoreCase("BYTE")) {
                throw new Exception("BYTE translation not supported");
            } else if (datatype.equalsIgnoreCase("SHORT")) {
                max += len / 2;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getShort();
                    if (v != ndv && translation.get((int) (v * rescale)) == null) {
                        v = v;
                    }
                    if (v != ndv && translation.get((int) (v * rescale)) != null)
                        v = translation.get((int) (v * rescale));
                    bbout.putShort((short) v);
                }
            } else if (datatype.equalsIgnoreCase("INT")) {
                max += len / 4;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getInt();
                    if (v != ndv && translation.get((int) (v * rescale)) != null)
                        v = translation.get((int) (v * rescale));
                    bbout.putInt((int) v);
                }
            } else if (datatype.equalsIgnoreCase("LONG")) {
                max += len / 8;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getLong();
                    if (v != ndv && translation.get((int) (v * rescale)) != null)
                        v = translation.get((int) (v * rescale));
                    bbout.putLong((long) v);
                }
            } else if (datatype.equalsIgnoreCase("FLOAT")) {
                throw new Exception("FLOAT translation not supported");
            } else if (datatype.equalsIgnoreCase("DOUBLE")) {
                throw new Exception("DOUBLE translation not supported");
            } else {
                max += len / 4;
                for (; i < max; i++) {
                    // should not happen; catch anyway...
                }
            }

            out.write(bout, 0, (int) len);
        }

        writeHeader(filename + ".new", xmin, ymin, xmin + xres * ncols, ymin + yres * nrows, xres, yres, nrows,
                ncols, minv, maxv, datatype, nodatavalue + "");
    } catch (Exception e) {
        logger.error("An error has occurred getting grid class stats", e);
    } finally {
        if (afile != null) {
            try {
                afile.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }

        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

    try {
        if (!new File(filename + ".gri.old").exists())
            FileUtils.moveFile(new File(filename + ".gri"), new File(filename + ".gri.old"));
        if (!new File(filename + ".grd.old").exists())
            FileUtils.moveFile(new File(filename + ".grd"), new File(filename + ".grd.old"));

        FileUtils.moveFile(new File(filename + ".gri.new"), new File(filename + ".gri"));
        FileUtils.moveFile(new File(filename + ".new.grd"), new File(filename + ".grd"));
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private GBDeviceEvent[] decodeDictToJSONAppMessage(UUID uuid, ByteBuffer buf) throws JSONException {
    buf.order(ByteOrder.LITTLE_ENDIAN);
    byte dictSize = buf.get();
    if (dictSize == 0) {
        LOG.info("dict size is 0, ignoring");
        return null;
    }/*from   w  w  w.j a v  a  2s  .  co m*/
    JSONArray jsonArray = new JSONArray();
    while (dictSize-- > 0) {
        JSONObject jsonObject = new JSONObject();
        Integer key = buf.getInt();
        byte type = buf.get();
        short length = buf.getShort();
        jsonObject.put("key", key);
        if (type == TYPE_CSTRING) {
            length--;
        }
        jsonObject.put("length", length);
        switch (type) {
        case TYPE_UINT:
            jsonObject.put("type", "uint");
            if (length == 1) {
                jsonObject.put("value", buf.get() & 0xff);
            } else if (length == 2) {
                jsonObject.put("value", buf.getShort() & 0xffff);
            } else {
                jsonObject.put("value", buf.getInt() & 0xffffffffL);
            }
            break;
        case TYPE_INT:
            jsonObject.put("type", "int");
            if (length == 1) {
                jsonObject.put("value", buf.get());
            } else if (length == 2) {
                jsonObject.put("value", buf.getShort());
            } else {
                jsonObject.put("value", buf.getInt());
            }
            break;
        case TYPE_BYTEARRAY:
        case TYPE_CSTRING:
            byte[] bytes = new byte[length];
            buf.get(bytes);
            if (type == TYPE_BYTEARRAY) {
                jsonObject.put("type", "bytes");
                jsonObject.put("value", new String(Base64.encode(bytes, Base64.NO_WRAP)));
            } else {
                jsonObject.put("type", "string");
                jsonObject.put("value", new String(bytes));
                buf.get(); // skip null-termination;
            }
            break;
        default:
            LOG.info("unknown type in appmessage, ignoring");
            return null;
        }
        jsonArray.put(jsonObject);
    }

    GBDeviceEventSendBytes sendBytesAck = null;
    if (mAlwaysACKPebbleKit) {
        // this is a hack we send an ack to the Pebble immediately because somebody said it helps some PebbleKit apps :P
        sendBytesAck = new GBDeviceEventSendBytes();
        sendBytesAck.encodedBytes = encodeApplicationMessageAck(uuid, last_id);
    }
    GBDeviceEventAppMessage appMessage = new GBDeviceEventAppMessage();
    appMessage.appUUID = uuid;
    appMessage.id = last_id & 0xff;
    appMessage.message = jsonArray.toString();
    return new GBDeviceEvent[] { appMessage, sendBytesAck };
}

From source file:com.skratchdot.electribe.model.esx.impl.SampleImpl.java

/**
 * <!-- begin-user-doc -->// w w w  .  j a v  a  2  s.  c om
 * @return Returns a byte array that combines/mixes channel1 and channel2
 * <!-- end-user-doc -->
 * @generated NOT
 */
public byte[] getAudioDataChannelBoth() {
    if (this.isEmpty()) {
        return new byte[0];
    }
    ByteBuffer bufferChannel1 = ByteBuffer.wrap(this.getAudioDataChannel1());
    ByteBuffer bufferChannel2 = ByteBuffer.wrap(this.getAudioDataChannel2());
    ByteBuffer bufferChannelBoth = ByteBuffer.allocate(bufferChannel1.capacity());
    int dataChannel1;
    int dataChannel2;
    short dataChannelBoth;
    for (int j = 0; j < this.getNumberOfSampleFrames(); j++) {
        dataChannel1 = bufferChannel1.getShort();
        dataChannel2 = bufferChannel2.getShort();
        dataChannelBoth = (short) ((dataChannel1 + dataChannel2) / 2);
        bufferChannelBoth.putShort(dataChannelBoth);
    }
    return bufferChannelBoth.array();
}

From source file:au.org.ala.layers.intersect.Grid.java

public float[] getGrid() {
    int maxArrayLength = Integer.MAX_VALUE - 10;

    if (grid_data != null) {
        return grid_data;
    }//from www. j  a v  a 2s. c  om

    Grid loadedAlready = getLoadedGrid(filename);
    if (loadedAlready != null && loadedAlready.grid_data != null) {
        return loadedAlready.grid_data;
    }

    int length = nrows * ncols;

    float[] ret = new float[length];

    RandomAccessFile afile = null;
    File f2 = new File(filename + ".GRI");

    try { //read of random access file can throw an exception
        if (!f2.exists()) {
            afile = new RandomAccessFile(filename + ".gri", "r");
        } else {
            afile = new RandomAccessFile(filename + ".GRI", "r");
        }

        byte[] b = new byte[(int) Math.min(afile.length(), maxArrayLength)];

        int i = 0;
        int max = 0;
        int len;
        while ((len = afile.read(b)) > 0) {
            ByteBuffer bb = ByteBuffer.wrap(b);

            if (byteorderLSB) {
                bb.order(ByteOrder.LITTLE_ENDIAN);
            }

            if (datatype.equalsIgnoreCase("UBYTE")) {
                max += len;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.get();
                    if (ret[i] < 0) {
                        ret[i] += 256;
                    }
                }
            } else if (datatype.equalsIgnoreCase("BYTE")) {
                max += len;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.get();
                }
            } else if (datatype.equalsIgnoreCase("SHORT")) {
                max += len / 2;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.getShort();
                }
            } else if (datatype.equalsIgnoreCase("INT")) {
                max += len / 4;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.getInt();
                }
            } else if (datatype.equalsIgnoreCase("LONG")) {
                max += len / 8;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.getLong();
                }
            } else if (datatype.equalsIgnoreCase("FLOAT")) {
                max += len / 4;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = bb.getFloat();
                }
            } else if (datatype.equalsIgnoreCase("DOUBLE")) {
                max += len / 8;
                max = Math.min(max, ret.length);
                for (; i < max; i++) {
                    ret[i] = (float) bb.getDouble();
                }
            } else {
                // / should not happen; catch anyway...
                max += len / 4;
                for (; i < max; i++) {
                    ret[i] = Float.NaN;
                }
            }
        }

        //replace not a number
        for (i = 0; i < length; i++) {
            if ((float) ret[i] == (float) nodatavalue) {
                ret[i] = Float.NaN;
            } else {
                ret[i] *= rescale;
            }
        }
    } catch (Exception e) {
        logger.error("An error has occurred - probably a file error", e);
    } finally {
        if (afile != null) {
            try {
                afile.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    grid_data = ret;
    return ret;
}

From source file:au.org.ala.layers.intersect.Grid.java

public void getClassInfo(Map<Float, float[]> info) {

    long length = ((long) nrows) * ((long) ncols);

    RandomAccessFile afile = null;
    File f2 = new File(filename + ".GRI");

    try { //read of random access file can throw an exception
        if (!f2.exists()) {
            afile = new RandomAccessFile(filename + ".gri", "r");
        } else {//  www.  j a v  a2s .  c o m
            afile = new RandomAccessFile(filename + ".GRI", "r");
        }

        byte[] b = new byte[65536];

        long i = 0;
        long max = 0;
        long len;
        float v;
        float ndv = (float) nodatavalue;

        while ((len = afile.read(b)) > 0) {
            ByteBuffer bb = ByteBuffer.wrap(b);

            if (byteorderLSB) {
                bb.order(ByteOrder.LITTLE_ENDIAN);
            }

            if (datatype.equalsIgnoreCase("UBYTE")) {
                max += len;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.get();
                    if (v < 0)
                        v += 256;
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("BYTE")) {
                max += len;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.get();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("SHORT")) {
                max += len / 2;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getShort();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("INT")) {
                max += len / 4;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getInt();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("LONG")) {
                max += len / 8;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getLong();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("FLOAT")) {
                max += len / 4;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = bb.getFloat();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else if (datatype.equalsIgnoreCase("DOUBLE")) {
                max += len / 8;
                max = Math.min(max, length);
                for (; i < max; i++) {
                    v = (float) bb.getDouble();
                    if (v != ndv)
                        updatesStats(info, i, v * rescale);
                }
            } else {
                max += len / 4;
                for (; i < max; i++) {
                    // should not happen; catch anyway...
                }
            }
        }
    } catch (Exception e) {
        logger.error("An error has occurred getting grid class stats", e);
    } finally {
        if (afile != null) {
            try {
                afile.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

}

From source file:com.l2jfree.gameserver.network.L2ClientPacketHandlerFinal.java

@Override
public L2ClientPacket handlePacket(ByteBuffer buf, L2Client client, final int opcode) {
    L2ClientPacket msg = null;// w w  w .  j  a v a  2  s. c om
    GameClientState state = client.getState();

    switch (state) {
    case CONNECTED:
        switch (opcode) {
        case 0x0e:
            msg = new ProtocolVersion();
            break;
        case 0x2b:
            msg = new AuthLogin();
            break;
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    case AUTHED:
        switch (opcode) {
        case 0x00:
            msg = new Logout();
            break;
        case 0x0c:
            msg = new NewCharacter();
            break;
        case 0x0d:
            msg = new CharacterDelete();
            break;
        case 0x0f:
            // MoveBackwardsToLocation, lag issue
            break;
        case 0x12:
            msg = new CharacterSelected();
            break;
        case 0x13:
            msg = new NewCharacterInit();
            break;
        case 0x57:
            // RequestRestart, lag issue
            break;
        case 0x7b:
            msg = new CharacterRestore();
            break;
        case 0xd0:
            int id2 = -1;
            if (buf.remaining() >= 2) {
                id2 = buf.getShort() & 0xffff;
            } else {
                if (Config.PACKET_HANDLER_DEBUG)
                    _log.warn("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
                break;
            }

            switch (id2) {
            case 0x24:
                // RequestSaveInventoryOrder, lag issue
                break;
            case 0x36:
                msg = new CharacterPrevState();
                break;
            case 0x39:
                // most probably using L2NET
                break;
            case 0x3d: // client definitely sends it right now, enable if supposed to be
                //msg = new RequestAllFortressInfo();
                break;
            case 0x5a:
                int id3 = 0;
                if (buf.remaining() >= 4) {
                    id3 = buf.getInt() & 0xffffffff;
                } else {
                    if (Config.PACKET_HANDLER_DEBUG)
                        _log.warn("Client: " + client + " sent a 0xd0:0x5a without the third opcode.");
                    break;
                }

                switch (id3) {
                case 0x00:
                    msg = new RequestExCubeGameChangeTeam();
                    break;
                default:
                    printDebug(buf, client, opcode, id2, id3);
                    break;
                }
                break;
            default:
                printDebug(buf, client, opcode, id2);
            }
            break;
        // to avoid unnecessary warning about invalid opcode (if the client lags a bit, then it starts spamming this packet)
        case 0x59: // ValidatePosition
            break;
        //
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    case IN_GAME:
        switch (opcode) {
        // to avoid unnecessary warning about invalid opcode (player clicked the button multiple times)
        case 0x12: // CharacterSelected
            break;
        //
        case 0x00:
            msg = new Logout();
            break;
        case 0x01:
            msg = new AttackRequest();
            break;
        case 0x03:
            msg = new RequestStartPledgeWar();
            break;
        case 0x04:
            msg = new RequestReplyStartPledgeWar();
            break;
        case 0x05:
            msg = new RequestStopPledgeWar();
            break;
        case 0x06: // RequestSCCheck
            msg = new RequestReplyStopPledgeWar();
            break;
        case 0x07:
            msg = new RequestSurrenderPledgeWar();
            break;
        case 0x08:
            msg = new RequestReplySurrenderPledgeWar();
            break;
        case 0x09:
            msg = new RequestSetPledgeCrest();
            break;
        case 0x0b:
            msg = new RequestGiveNickName();
            break;
        case 0x0f:
            msg = new MoveBackwardToLocation();
            break;
        case 0x10:
            // Say
            break;
        case 0x11:
            msg = new EnterWorld();
            break;
        case 0x14:
            msg = new RequestItemList();
            break;
        case 0x15:
            // RequestEquipItem
            break;
        case 0x16:
            msg = new RequestUnEquipItem();
            break;
        case 0x17:
            msg = new RequestDropItem();
            break;
        case 0x19:
            msg = new UseItem();
            break;
        case 0x1a:
            msg = new TradeRequest();
            break;
        case 0x1b:
            msg = new AddTradeItem();
            break;
        case 0x1c:
            msg = new TradeDone();
            break;
        case 0x1f:
            msg = new Action();
            break;
        case 0x22:
            msg = new RequestLinkHtml();
            break;
        case 0x23:
            msg = new RequestBypassToServer();
            break;
        case 0x24:
            msg = new RequestBBSwrite();
            break;
        case 0x25:
            // RequestCreatePledge
            break;
        case 0x26:
            msg = new RequestJoinPledge();
            break;
        case 0x27:
            msg = new RequestAnswerJoinPledge();
            break;
        case 0x28:
            msg = new RequestWithdrawalPledge();
            break;
        case 0x29:
            msg = new RequestOustPledgeMember();
            break;
        case 0x2c:
            msg = new RequestGetItemFromPet();
            break;
        case 0x2e:
            msg = new RequestAllyInfo();
            break;
        case 0x2f:
            msg = new RequestCrystallizeItem();
            break;
        case 0x30:
            msg = new RequestPrivateStoreManageSell();
            break;
        case 0x31:
            msg = new SetPrivateStoreListSell();
            break;
        case 0x32:
            msg = new AttackRequest();
            break;
        case 0x33:
            // RequestTeleportPacket
            break;
        case 0x34:
            msg = new RequestSocialAction();
            break;
        case 0x35:
            msg = new ChangeMoveType();
            break;
        case 0x36:
            msg = new ChangeWaitType();
            break;
        case 0x37:
            msg = new RequestSellItem();
            break;
        case 0x38:
            // RequestMagicSkillList
            break;
        case 0x39:
            msg = new RequestMagicSkillUse();
            break;
        case 0x3a:
            msg = new SendAppearing();
            break;
        case 0x3b:
            if (Config.ALLOW_WAREHOUSE)
                msg = new SendWareHouseDepositList();
            break;
        case 0x3c:
            msg = new SendWareHouseWithDrawList();
            break;
        case 0x3d:
            msg = new RequestShortCutReg();
            break;
        case 0x3f:
            msg = new RequestShortCutDel();
            break;
        case 0x40:
            msg = new RequestBuyItem();
            break;
        case 0x41:
            // RequestDismissPledge
            break;
        case 0x42:
            msg = new RequestJoinParty();
            break;
        case 0x43:
            msg = new RequestAnswerJoinParty();
            break;
        case 0x44:
            msg = new RequestWithDrawalParty();
            break;
        case 0x45:
            msg = new RequestOustPartyMember();
            break;
        case 0x46:
            // RequestDismissParty
            break;
        case 0x47:
            msg = new CannotMoveAnymore();
            break;
        case 0x48:
            msg = new RequestTargetCanceld();
            break;
        case 0x49:
            msg = new Say2();
            break;
        case 0x4a:
            int id_2 = -1;
            if (buf.remaining() >= 2) {
                id_2 = buf.get() & 0xff;
            } else {
                if (Config.PACKET_HANDLER_DEBUG)
                    _log.warn("Client: " + client.toString() + " sent a 0x4a without the second opcode.");
                break;
            }

            switch (id_2) {
            case 0x00:
                msg = new SuperCmdCharacterInfo();
                break;
            case 0x01:
                msg = new SuperCmdSummonCmd();
                break;
            case 0x02:
                msg = new SuperCmdServerStatus();
                break;
            case 0x03:
                msg = new SendL2ParamSetting();
                break;
            default:
                printDebug(buf, client, opcode, id_2);
                break;
            }
            break;
        case 0x4d:
            msg = new RequestPledgeMemberList();
            break;
        case 0x4f:
            //RequestMagicList
            break;
        case 0x50:
            msg = new RequestSkillList();
            break;
        case 0x52:
            msg = new MoveWithDelta();
            break;
        case 0x53:
            msg = new RequestGetOnVehicle();
            break;
        case 0x54:
            msg = new RequestGetOffVehicle();
            break;
        case 0x55:
            msg = new AnswerTradeRequest();
            break;
        case 0x56:
            msg = new RequestActionUse();
            break;
        case 0x57:
            msg = new RequestRestart();
            break;
        case 0x58:
            msg = new RequestSiegeInfo();
            break;
        case 0x59:
            msg = new ValidatePosition();
            break;
        case 0x5a:
            // RequestSEKCustom
            break;
        case 0x5b:
            // StartRotating
            break;
        case 0x5c:
            // FinishRotating
            break;
        case 0x5e:
            msg = new RequestShowBoard();
            break;
        case 0x5f:
            msg = new RequestEnchantItem();
            break;
        case 0x60:
            msg = new RequestDestroyItem();
            break;
        case 0x62:
            msg = new RequestQuestList();
            break;
        case 0x63: // RequestDestroyQuest
            msg = new RequestQuestAbort();
            break;
        case 0x65:
            msg = new RequestPledgeInfo();
            break;
        case 0x66:
            msg = new RequestPledgeExtendedInfo();
            break;
        case 0x67:
            msg = new RequestPledgeCrest();
            break;
        case 0x6b:
            msg = new RequestSendFriendMsg();
            break;
        case 0x6c:
            msg = new RequestShowMiniMap();
            break;
        case 0x6d:
            // RequestSendMsnChatLog
            break;
        case 0x6e: //RequestReload
            msg = new RequestRecordInfo();
            break;
        case 0x6f:
            msg = new RequestHennaEquip();
            break;
        case 0x70:
            msg = new RequestHennaRemoveList();
            break;
        case 0x71:
            msg = new RequestHennaItemRemoveInfo();
            break;
        case 0x72:
            msg = new RequestHennaRemove();
            break;
        case 0x73:
            msg = new RequestAquireSkillInfo();
            break;
        case 0x74:
            msg = new SendBypassBuildCmd();
            break;
        case 0x75:
            msg = new RequestMoveToLocationInVehicle();
            break;
        case 0x76:
            msg = new CannotMoveAnymoreInVehicle();
            break;
        case 0x77:
            msg = new RequestFriendInvite();
            break;
        case 0x78:
            msg = new RequestAnswerFriendInvite();
            break;
        case 0x79:
            msg = new RequestFriendList();
            break;
        case 0x7a:
            msg = new RequestFriendDel();
            break;
        case 0x7c: // send when a skill to be learned is selected
            msg = new RequestAquireSkill();
            break;
        case 0x7d:
            msg = new RequestRestartPoint();
            break;
        case 0x7e:
            msg = new RequestGMCommand();
            break;
        case 0x7f:
            msg = new RequestPartyMatchConfig();
            break;
        case 0x80:
            msg = new RequestPartyMatchList();
            break;
        case 0x81:
            msg = new RequestPartyMatchDetail();
            break;
        case 0x83:
            msg = new RequestPrivateStoreBuy();
            break;
        case 0x85:
            msg = new RequestTutorialLinkHtml();
            break;
        case 0x86:
            msg = new RequestTutorialPassCmdToServer();
            break;
        case 0x87:
            msg = new RequestTutorialQuestionMark();
            break;
        case 0x88:
            msg = new RequestTutorialClientEvent();
            break;
        case 0x89:
            msg = new RequestPetition();
            break;
        case 0x8a:
            msg = new RequestPetitionCancel();
            break;
        case 0x8b:
            msg = new RequestGmList();
            break;
        case 0x8c:
            msg = new RequestJoinAlly();
            break;
        case 0x8d:
            msg = new RequestAnswerJoinAlly();
            break;
        case 0x8e:
            msg = new RequestWithdrawAlly();
            break;
        case 0x8f:
            msg = new RequestOustAlly();
            break;
        case 0x90:
            msg = new RequestDismissAlly();
            break;
        case 0x91:
            msg = new RequestSetAllyCrest();
            break;
        case 0x92:
            msg = new RequestAllyCrest();
            break;
        case 0x93:
            msg = new RequestChangePetName();
            break;
        case 0x94:
            msg = new RequestPetUseItem();
            break;
        case 0x95:
            msg = new RequestGiveItemToPet();
            break;
        case 0x96:
            msg = new RequestPrivateStoreQuitSell();
            break;
        case 0x97:
            msg = new SetPrivateStoreMsgSell();
            break;
        case 0x98:
            msg = new RequestPetGetItem();
            break;
        case 0x99:
            msg = new RequestPrivateStoreManageBuy();
            break;
        case 0x9a:
            msg = new SetPrivateStoreListBuy();
            break;
        case 0x9c:
            msg = new RequestPrivateStoreQuitBuy();
            break;
        case 0x9d:
            msg = new SetPrivateStoreMsgBuy();
            break;
        case 0x9f: // SendPrivateStoreBuyList
            msg = new RequestPrivateStoreSell();
            break;
        case 0xa0:
            //SendTimeCheckPacket
            break;
        case 0xa6:
            // RequestSkillCoolTime
            break;
        case 0xa7:
            msg = new RequestPackageSendableItemList();
            break;
        case 0xa8:
            msg = new RequestPackageSend();
            break;
        case 0xa9:
            msg = new RequestBlock();
            break;
        case 0xaa:
            msg = new RequestSiegeInfo();
            break;
        case 0xab:
            msg = new RequestSiegeAttackerList();
            break;
        case 0xac:
            msg = new RequestSiegeDefenderList();
            break;
        case 0xad:
            msg = new RequestJoinSiege();
            break;
        case 0xae:
            msg = new RequestConfirmSiegeWaitingList();
            break;
        case 0xaf:
            // RequestSetCastleSiegeTime
            break;
        case 0xb0:
            msg = new MultiSellChoose();
            break;
        case 0xb1:
            // NetPing
            break;
        case 0xb2:
            msg = new RequestRemainTime();
            break;
        case 0xb3:
            msg = new BypassUserCmd();
            break;
        case 0xb4:
            msg = new SnoopQuit();
            break;
        case 0xb5:
            msg = new RequestRecipeBookOpen();
            break;
        case 0xb6: // RequestRecipeItemDelete
            msg = new RequestRecipeBookDestroy();
            break;
        case 0xb7:
            msg = new RequestRecipeItemMakeInfo();
            break;
        case 0xb8:
            msg = new RequestRecipeItemMakeSelf();
            break;
        case 0xb9:
            // RequestRecipeShopManageList
            break;
        case 0xba:
            msg = new RequestRecipeShopMessageSet();
            break;
        case 0xbb:
            msg = new RequestRecipeShopListSet();
            break;
        case 0xbc:
            msg = new RequestRecipeShopManageQuit();
            break;
        case 0xbd:
            // RequestRecipeShopManageCancel
            break;
        case 0xbe:
            msg = new RequestRecipeShopMakeInfo();
            break;
        case 0xbf:
            msg = new RequestRecipeShopMakeItem();
            break;
        case 0xc0:
            msg = new RequestRecipeShopSellList();
            break;
        case 0xc1:
            msg = new RequestObserverEnd();
            break;
        case 0xc2: // VoteSociality
            msg = new VoteSociality();
            break;
        case 0xc3: // RequestHennaItemList
            msg = new RequestHennaDrawList();
            break;
        case 0xc4:
            msg = new RequestHennaItemDrawInfo();
            break;
        case 0xc5:
            msg = new RequestBuySeed();
            break;
        case 0xc6:
            msg = new ConfirmDlgAnswer();
            break;
        case 0xc7:
            msg = new RequestWearItem();
            break;
        case 0xc8:
            msg = new RequestSSQStatus();
            break;
        case 0xc9:
            // PetitionVote
            break;
        case 0xcb:
            msg = new GameGuardReply();
            break;
        case 0xcc:
            // Clan Privileges
            msg = new RequestPledgePower();
            break;
        case 0xcd:
            msg = new RequestMakeMacro();
            break;
        case 0xce:
            msg = new RequestDeleteMacro();
            break;
        // Manor
        case 0xcf: // RequestProcureCrop
            msg = new RequestBuyProcure();
            break;
        case 0xd0:
            int id2 = -1;
            if (buf.remaining() >= 2) {
                id2 = buf.getShort() & 0xffff;
            } else {
                if (Config.PACKET_HANDLER_DEBUG)
                    _log.warn("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
                break;
            }

            switch (id2) {
            case 0x01:
                msg = new RequestManorList();
                break;
            case 0x02:
                msg = new RequestProcureCropList();
                break;
            case 0x03:
                msg = new RequestSetSeed();
                break;
            case 0x04:
                msg = new RequestSetCrop();
                break;
            case 0x05:
                msg = new RequestWriteHeroWords();
                break;
            case 0x06:
                msg = new RequestExAskJoinMPCC();
                break;
            case 0x07:
                msg = new RequestExAcceptJoinMPCC();
                break;
            case 0x08:
                msg = new RequestExOustFromMPCC();
                break;
            case 0x09:
                msg = new RequestOustFromPartyRoom();
                break;
            case 0x0a:
                msg = new RequestDismissPartyRoom();
                break;
            case 0x0b:
                msg = new RequestWithdrawPartyRoom();
                break;
            case 0x0c:
                msg = new RequestChangePartyLeader();
                break;
            case 0x0d:
                msg = new RequestAutoSoulShot();
                break;
            case 0x0e:
                msg = new RequestExEnchantSkillInfo();
                break;
            case 0x0f:
                msg = new RequestExEnchantSkill();
                break;
            case 0x10:
                msg = new RequestExPledgeCrestLarge();
                break;
            case 0x11:
                msg = new RequestExSetPledgeCrestLarge();
                break;
            case 0x12:
                msg = new RequestPledgeSetAcademyMaster();
                break;
            case 0x13:
                msg = new RequestPledgePowerGradeList();
                break;
            case 0x14:
                msg = new RequestPledgeMemberPowerInfo();
                break;
            case 0x15:
                msg = new RequestPledgeSetMemberPowerGrade();
                break;
            case 0x16:
                msg = new RequestPledgeMemberInfo();
                break;
            case 0x17:
                msg = new RequestPledgeWarList();
                break;
            case 0x18:
                msg = new RequestExFishRanking();
                break;
            case 0x19:
                msg = new RequestPCCafeCouponUse();
                break;
            case 0x1b:
                msg = new RequestDuelStart();
                break;
            case 0x1c:
                msg = new RequestDuelAnswerStart();
                break;
            case 0x1d:
                // RequestExSetTutorial
                break;
            case 0x1e:
                msg = new RequestExRqItemLink();
                break;
            case 0x1f:
                // CanNotMoveAnymoreAirShip
                break;
            case 0x20:
                msg = new MoveToLocationInAirShip();
                break;
            case 0x21:
                msg = new RequestKeyMapping();
                break;
            case 0x22:
                // RequestSaveKeyMapping
                break;
            case 0x23:
                msg = new RequestExRemoveItemAttribute();
                break;
            case 0x24:
                msg = new RequestSaveInventoryOrder();
                break;
            case 0x25:
                msg = new RequestExitPartyMatchingWaitingRoom();
                break;
            case 0x26:
                msg = new RequestConfirmTargetItem();
                break;
            case 0x27:
                msg = new RequestConfirmRefinerItem();
                break;
            case 0x28:
                msg = new RequestConfirmGemStone();
                break;
            case 0x29:
                msg = new RequestOlympiadObserverEnd();
                break;
            case 0x2a:
                msg = new RequestCursedWeaponList();
                break;
            case 0x2b:
                msg = new RequestCursedWeaponLocation();
                break;
            case 0x2c:
                msg = new RequestPledgeReorganizeMember();
                break;
            case 0x2d:
                msg = new RequestExMPCCShowPartyMembersInfo();
                break;
            case 0x2e:
                msg = new RequestOlympiadMatchList();
                break;
            case 0x2f:
                msg = new RequestAskJoinPartyRoom();
                break;
            case 0x30:
                msg = new AnswerJoinPartyRoom();
                break;
            case 0x31:
                msg = new RequestListPartyMatchingWaitingRoom();
                break;
            case 0x32:
                msg = new RequestExEnchantSkillSafe();
                break;
            case 0x33:
                msg = new RequestExEnchantSkillUntrain();
                break;
            case 0x34:
                msg = new RequestExEnchantSkillRouteChange();
                break;
            case 0x35:
                msg = new RequestExEnchantItemAttribute();
                break;
            case 0x36:
                msg = new ExGetOnAirShip();
                break;
            case 0x38:
                // MoveToLocationAirShip
                break;
            case 0x39:
                msg = new RequestBidItemAuction();
                break;
            case 0x3a:
                msg = new RequestInfoItemAuction();
                break;
            case 0x3b:
                msg = new RequestExChangeName();
                break;
            case 0x3c:
                msg = new RequestAllCastleInfo();
                break;
            case 0x3d:
                msg = new RequestAllFortressInfo();
                break;
            case 0x3e:
                msg = new RequestAllAgitInfo();
                break;
            case 0x3f:
                msg = new RequestFortressSiegeInfo();
                break;
            case 0x40:
                msg = new RequestGetBossRecord();
                break;
            case 0x41:
                msg = new RequestRefine();
                break;
            case 0x42:
                msg = new RequestConfirmCancelItem();
                break;
            case 0x43:
                msg = new RequestRefineCancel();
                break;
            case 0x44:
                msg = new RequestExMagicSkillUseGround();
                break;
            case 0x45:
                msg = new RequestDuelSurrender();
                break;
            case 0x46:
                msg = new RequestExEnchantSkillInfoDetail();
                break;
            case 0x48:
                msg = new RequestFortressMapInfo();
                break;
            case 0x49:
                msg = new RequestPVPMatchRecord();
                break;
            case 0x4a:
                msg = new SetPrivateStoreWholeMsg();
                break;
            case 0x4b:
                msg = new RequestDispel();
                break;
            case 0x4c:
                msg = new RequestExTryToPutEnchantTargetItem();
                break;
            case 0x4d:
                msg = new RequestExTryToPutEnchantSupportItem();
                break;
            case 0x4e:
                msg = new RequestExCancelEnchantItem();
                break;
            case 0x4f:
                msg = new RequestChangeNicknameColor();
                break;
            case 0x50:
                msg = new RequestResetNickname();
                break;
            case 0x51:
                int id3 = 0;
                if (buf.remaining() >= 4) {
                    id3 = buf.getInt() & 0xffffffff;
                } else {
                    if (Config.PACKET_HANDLER_DEBUG)
                        _log.warn("Client: " + client + " sent a 0xd0:0x51 without the third opcode.");
                    break;
                }

                switch (id3) {
                case 0x00:
                    msg = new RequestBookMarkSlotInfo();
                    break;
                case 0x01:
                    msg = new RequestSaveBookMarkSlot();
                    break;
                case 0x02:
                    msg = new RequestModifyBookMarkSlot();
                    break;
                case 0x03:
                    msg = new RequestDeleteBookMarkSlot();
                    break;
                case 0x04:
                    msg = new RequestTeleportBookMark();
                    break;
                case 0x05:
                    // RequestChangeBookMarkSlot
                    break;
                default:
                    printDebug(buf, client, opcode, id2, id3);
                    break;
                }
                break;
            case 0x52:
                msg = new RequestWithDrawPremiumItem();
                break;
            case 0x53:
                msg = new RequestJump();
                break;
            case 0x54:
                msg = new RequestStartShowCrataeCubeRank();
                break;
            case 0x55:
                msg = new RequestStopShowCrataeCubeRank();
                break;
            case 0x56:
                msg = new NotifyStartMiniGame();
                break;
            case 0x57:
                msg = new RequestJoinDominionWar();
                break;
            case 0x58:
                msg = new RequestDominionInfo();
                break;
            case 0x59:
                msg = new RequestExCleftEnter();
                break;
            case 0x5a:
                id3 = 0;
                if (buf.remaining() >= 4) {
                    id3 = buf.getInt() & 0xffffffff;
                } else {
                    _log.warn("Client: " + client + " sent a 0xd0:0x5a without the third opcode.");
                    break;
                }

                switch (id3) {
                case 0x00:
                    msg = new RequestExCubeGameChangeTeam();
                    break;
                default:
                    printDebug(buf, client, opcode, id2, id3);
                    break;
                }
                break;
            case 0x5b:
                msg = new EndScenePlayer();
                break;
            case 0x5c:
                msg = new RequestExBlockGameVote();
                break;
            case 0x63:
                msg = new RequestSeedPhase();
                break;
            case 0x65:
                msg = new BrGamePoint();
                break;
            case 0x66:
                msg = new BrProductList();
                break;
            case 0x67:
                msg = new BrProductInfo();
                break;
            case 0x68:
                msg = new BrBuyProduct();
                break;
            default:
                printDebug(buf, client, opcode, id2);
                break;
            }
            break;
        /*
        * case 0xee: msg = new RequestChangePartyLeader(data,
        * _client); break;
        */
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    }
    return msg;
}

From source file:com.l2jfree.gameserver.network.L2ClientPacketHandler.java

@Override
public L2ClientPacket handlePacket(ByteBuffer buf, L2Client client, final int opcode) {
    L2ClientPacket msg = null;//from w w w.  j  av a2 s . c  o  m
    GameClientState state = client.getState();

    switch (state) {
    case CONNECTED:
        switch (opcode) {
        /* Commented out by Kerberos: not useful anymore
        case 0x00:
           if (Config.PACKET_HANDLER_DEBUG)
          _log.warn("Client " + client.toString() + " is trying to connect using Interlude Client");
           break;
        */
        case 0x0e:
            msg = new ProtocolVersion();
            break;
        case 0x2b:
            msg = new AuthLogin();
            break;
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    case AUTHED:
        switch (opcode) {
        case 0x00:
            msg = new Logout();
            break;
        case 0x0c:
            msg = new NewCharacter();
            break;
        case 0x0d:
            msg = new CharacterDelete();
            break;
        case 0x12:
            msg = new CharacterSelected();
            break;
        case 0x13:
            msg = new NewCharacterInit();
            break;
        /* Commented out by Kerberos: not being used anymore
        case 0x54:
          // client send this packet when u are on boat and u relog game X_x
          break;
        */
        case 0x67:
            msg = new RequestPledgeCrest();
            break;
        case 0x7b:
            msg = new CharacterRestore();
            break;
        case 0xd0:
            int id2 = -1;
            if (buf.remaining() >= 2) {
                id2 = buf.getShort() & 0xffff;
            } else {
                if (Config.PACKET_HANDLER_DEBUG)
                    _log.warn("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
                break;
            }

            // single packet
            if (id2 == 0x39 || id2 == 0x36) {
                msg = new CharacterPrevState();
            } else {
                printDebug(buf, client, opcode, id2);
            }

            break;
        // to avoid unnecessary warning about invalid opcode (if the client lags a bit, then it starts spamming this packet)
        case 0x59: // ValidatePosition
            break;
        //
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    case IN_GAME:
        switch (opcode) {
        // to avoid unnecessary warning about invalid opcode (player clicked the button multiple times)
        case 0x12: // CharacterSelected
            break;
        //
        case 0x00:
            msg = new Logout();
            break;
        case 0x01:
            msg = new AttackRequest();
            break;
        case 0x03:
            msg = new RequestStartPledgeWar();
            break;
        case 0x04:
            msg = new RequestReplyStartPledgeWar();
            break;
        case 0x05:
            msg = new RequestStopPledgeWar();
            break;
        case 0x06:
            msg = new RequestReplyStopPledgeWar();
            break;
        case 0x07:
            msg = new RequestSurrenderPledgeWar();
            break;
        case 0x08:
            msg = new RequestReplySurrenderPledgeWar();
            break;
        case 0x09:
            msg = new RequestSetPledgeCrest();
            break;
        case 0x0b:
            msg = new RequestGiveNickName();
            break;
        case 0x0f:
            msg = new MoveBackwardToLocation();
            break;
        case 0x11:
            msg = new EnterWorld();
            break;
        case 0x14:
            msg = new RequestItemList();
            break;
        case 0x16:
            msg = new RequestUnEquipItem(); // confirm
            break;
        case 0x17:
            msg = new RequestDropItem();
            break;
        case 0x19:
            msg = new UseItem();
            break;
        case 0x1a:
            msg = new TradeRequest();
            break;
        case 0x1b:
            msg = new AddTradeItem();
            break;
        case 0x1c:
            msg = new TradeDone();
            break;
        case 0x1f:
            msg = new Action();
            break;
        case 0x22:
            msg = new RequestLinkHtml();
            break;
        case 0x23:
            msg = new RequestBypassToServer();
            break;
        case 0x24:
            msg = new RequestBBSwrite();
            break;
        case 0x26:
            msg = new RequestJoinPledge();
            break;
        case 0x27:
            msg = new RequestAnswerJoinPledge();
            break;
        case 0x28:
            msg = new RequestWithdrawalPledge();
            break;
        case 0x29:
            msg = new RequestOustPledgeMember();
            break;
        case 0x2c:
            msg = new RequestGetItemFromPet();
            break;
        case 0x2e:
            msg = new RequestAllyInfo();
            break;
        case 0x2f:
            msg = new RequestCrystallizeItem();
            break;
        case 0x30: // t1 ??
            msg = new RequestPrivateStoreManageSell();
            break;
        case 0x31: // t1 ??
            msg = new SetPrivateStoreListSell();
            break;
        //                  case 0x32:
        //                      msg = new RequestPrivateStoreManageCancel(data, _client);
        //                      break;
        case 0x34:
            msg = new RequestSocialAction();
            break;
        case 0x35:
            msg = new ChangeMoveType();
            break;
        case 0x36:
            msg = new ChangeWaitType();
            break;
        case 0x37:
            msg = new RequestSellItem();
            break;
        case 0x39:
            msg = new RequestMagicSkillUse();
            break;
        case 0x3a:
            msg = new SendAppearing(); //  (after death)
            break;
        case 0x3b:
            if (Config.ALLOW_WAREHOUSE)
                msg = new SendWareHouseDepositList();
            break;
        case 0x3c:
            msg = new SendWareHouseWithDrawList();
            break;
        case 0x3d:
            msg = new RequestShortCutReg();
            break;
        case 0x3f:
            msg = new RequestShortCutDel();
            break;
        case 0x40: // t1 ??
            msg = new RequestBuyItem();
            break;
        case 0x42:
            msg = new RequestJoinParty();
            break;
        case 0x43:
            msg = new RequestAnswerJoinParty();
            break;
        case 0x44:
            msg = new RequestWithDrawalParty();
            break;
        case 0x45:
            msg = new RequestOustPartyMember();
            break;
        case 0x46:
            // RequestDismissParty
            break;
        case 0x47:
            msg = new CannotMoveAnymore();
            break;
        case 0x48:
            msg = new RequestTargetCanceld();
            break;
        case 0x49:
            msg = new Say2();
            break;
        case 0x4d:
            msg = new RequestPledgeMemberList();
            break;
        case 0x4f:
            msg = new DummyPacket();
            break;
        case 0x50:
            msg = new RequestSkillList();
            break;
        case 0x52:
            msg = new MoveWithDelta();
            break;
        case 0x53:
            msg = new RequestGetOnVehicle();
            break;
        case 0x54:
            msg = new RequestGetOffVehicle();
            break;
        case 0x55:
            msg = new AnswerTradeRequest();
            break;
        case 0x56:
            msg = new RequestActionUse();
            break;
        case 0x57:
            msg = new RequestRestart();
            break;
        case 0x58:
            msg = new RequestSiegeInfo();
            break;
        case 0x59: // t1 ??
            msg = new ValidatePosition();
            break;
        //               case 0x5a:
        //                  // RequestSEKCustom
        //                  break;
        //                  THESE ARE NOW TEMPORARY DISABLED
        case 0x5b:
            //new StartRotating();
            break;
        case 0x5c:
            //new FinishRotating();
            break;
        case 0x5e:
            msg = new RequestShowBoard();
            break;
        case 0x5f:
            msg = new RequestEnchantItem();
            break;
        case 0x60:
            msg = new RequestDestroyItem();
            break;
        case 0x62:
            msg = new RequestQuestList();
            break;
        case 0x63:
            msg = new RequestQuestAbort();
            break;
        case 0x65:
            msg = new RequestPledgeInfo();
            break;
        case 0x66:
            msg = new RequestPledgeExtendedInfo();
            break;
        case 0x67:
            msg = new RequestPledgeCrest();
            break;
        case 0x6f:
            msg = new RequestHennaEquip();
            break;
        case 0x70:
            msg = new RequestHennaRemoveList();
            break;
        case 0x71:
            msg = new RequestHennaItemRemoveInfo();
            break;
        case 0x72:
            msg = new RequestHennaRemove();
            break;
        case 0x73: // send when talking to trainer npc, to show list of available skills
            msg = new RequestAquireSkillInfo();//  --> [s] 0xa4;
            break;
        case 0x74:
            msg = new SendBypassBuildCmd();
            break;
        case 0x75:
            msg = new RequestMoveToLocationInVehicle();
            break;
        case 0x76:
            msg = new CannotMoveAnymoreInVehicle();
            break;
        case 0x77:
            msg = new RequestFriendInvite();
            break;
        case 0x78:
            msg = new RequestAnswerFriendInvite();
            break;
        case 0x79:
            msg = new RequestFriendList();
            break;
        case 0x7a:
            msg = new RequestFriendDel();
            break;
        case 0x7c: // send when a skill to be learned is selected
            msg = new RequestAquireSkill();
            break;
        case 0x7d:
            msg = new RequestRestartPoint();
            break;
        case 0x7e:
            msg = new RequestGMCommand();
            break;
        case 0x7f:
            msg = new RequestPartyMatchConfig();
            break;
        case 0x80:
            msg = new RequestPartyMatchList();
            break;
        case 0x81:
            msg = new RequestPartyMatchDetail();
            break;
        //                      case 0x82:
        //                      // RequestPrivateStoreList
        //                      break;
        case 0x83:
            msg = new RequestPrivateStoreBuy();
            break;
        case 0x85:
            msg = new RequestTutorialLinkHtml();
            break;
        case 0x86:
            msg = new RequestTutorialPassCmdToServer();
            break;
        case 0x87:
            msg = new RequestTutorialQuestionMark();
            break;
        case 0x88:
            msg = new RequestTutorialClientEvent();
            break;
        case 0x89:
            msg = new RequestPetition();
            break;
        case 0x8a:
            msg = new RequestPetitionCancel();
            break;
        case 0x8b:
            msg = new RequestGmList();
            break;
        case 0x8c:
            msg = new RequestJoinAlly();
            break;
        case 0x8d:
            msg = new RequestAnswerJoinAlly();
            break;
        case 0x8e:
            msg = new RequestWithdrawAlly();
            break;
        case 0x8f:
            msg = new RequestOustAlly();
            break;
        case 0x90:
            msg = new RequestDismissAlly();
            break;
        case 0x91:
            msg = new RequestSetAllyCrest();
            break;
        case 0x92:
            msg = new RequestAllyCrest();
            break;
        case 0x93:
            msg = new RequestChangePetName();
            break;
        case 0x94:
            msg = new RequestPetUseItem();
            break;
        case 0x95:
            msg = new RequestGiveItemToPet();
            break;
        case 0x96:
            msg = new RequestPrivateStoreQuitSell();
            break;
        case 0x97:
            msg = new SetPrivateStoreMsgSell();
            break;
        case 0x98:
            msg = new RequestPetGetItem();
            break;
        case 0x99:
            msg = new RequestPrivateStoreManageBuy();
            break;
        case 0x9a:
            msg = new SetPrivateStoreListBuy();
            break;
        //               case 0x92:
        //                  // RequestPrivateStoreBuyManageCancel
        //                  break;
        case 0x9c:
            msg = new RequestPrivateStoreQuitBuy();
            break;
        case 0x9d:
            msg = new SetPrivateStoreMsgBuy();
            break;
        //               case 0x95:
        //                  // RequestPrivateStoreBuyList
        //                  break;
        case 0x9f:
            msg = new RequestPrivateStoreSell();
            break;
        //               case 0x97:
        //                  // SendTimeCheckPacket
        //                  break;
        //               case 0x98:
        //                  // RequestStartAllianceWar
        //                  break;
        //               case 0x99:
        //                  // ReplyStartAllianceWar
        //                  break;
        //               case 0x9a:
        //                  // RequestStopAllianceWar
        //                  break;
        //               case 0x9b:
        //                   // ReplyStopAllianceWar
        //                  break;
        //               case 0x9c:
        //                  // RequestSurrenderAllianceWar
        //                  break;
        case 0xa6:
            // RequestSkillCoolTime
            /*if (Config.DEBUG)
             _log.info("Request Skill Cool Time .. ignored");
            msg = null;*/
            break;
        case 0xa7:
            msg = new RequestPackageSendableItemList();
            break;
        case 0xa8:
            msg = new RequestPackageSend();
            break;
        case 0xa9:
            msg = new RequestBlock();
            break;
        case 0xaa:
            // RequestCastleSiegeInfo
            break;
        case 0xab:
            msg = new RequestSiegeAttackerList();
            break;
        case 0xac:
            msg = new RequestSiegeDefenderList();
            break;
        case 0xad:
            msg = new RequestJoinSiege();
            break;
        case 0xae:
            msg = new RequestConfirmSiegeWaitingList();
            break;
        //               case 0xaf:
        //                  // RequestSetCastleSiegeTime
        //                  break;
        case 0xb0:
            msg = new MultiSellChoose();
            break;
        //               case 0xb1:
        //                  // NetPing
        //                  break;
        case 0xb3:
            msg = new BypassUserCmd();
            break;
        case 0xb4:
            msg = new SnoopQuit();
            break;
        case 0xb5: // we still need this packet to handle BACK button of craft dialog
            msg = new RequestRecipeBookOpen();
            break;
        case 0xb6:
            msg = new RequestRecipeBookDestroy();
            break;
        case 0xb7:
            msg = new RequestRecipeItemMakeInfo();
            break;
        case 0xb8:
            msg = new RequestRecipeItemMakeSelf();
            break;
        //case 0xb9:
        //   msg = new RequestRecipeShopManageList(data, client);
        //    break;
        case 0xba:
            msg = new RequestRecipeShopMessageSet();
            break;
        case 0xbb:
            msg = new RequestRecipeShopListSet();
            break;
        case 0xbc:
            msg = new RequestRecipeShopManageQuit();
            break;
        case 0xbe:
            msg = new RequestRecipeShopMakeInfo();
            break;
        case 0xbf:
            msg = new RequestRecipeShopMakeItem();
            break;
        case 0xc0:
            msg = new RequestRecipeShopSellList();
            break;
        case 0xc1:
            msg = new RequestObserverEnd();
            break;
        case 0xc2:
            msg = new VoteSociality();
            break;
        case 0xc3:
            msg = new RequestHennaDrawList();
            break;
        case 0xc4:
            msg = new RequestHennaItemDrawInfo();
            break;
        case 0xcc:
            // Clan Privileges
            msg = new RequestPledgePower();
            break;
        case 0xcd:
            msg = new RequestMakeMacro();
            break;
        case 0xce:
            msg = new RequestDeleteMacro();
            break;
        // Manor
        case 0xcf:
            msg = new RequestBuyProcure();
            break;
        case 0xc5:
            msg = new RequestBuySeed();
            break;
        case 0xc6:
            msg = new ConfirmDlgAnswer();
            break;
        case 0xc7:
            msg = new RequestWearItem();
            break;
        case 0xc8:
            msg = new RequestSSQStatus();
            break;
        case 0xcb:
            msg = new GameGuardReply();
            break;
        case 0x6b:
            msg = new RequestSendFriendMsg();
            break;
        case 0x6c:
            msg = new RequestShowMiniMap();
            break;
        case 0x6d: // MSN dialogs so that you dont see them in the console.
            break;
        case 0x6e: //record video
            msg = new RequestRecordInfo();
            break;

        case 0xd0:
            int id2 = -1;
            if (buf.remaining() >= 2) {
                id2 = buf.getShort() & 0xffff;
            } else {
                if (Config.PACKET_HANDLER_DEBUG)
                    _log.warn("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
                break;
            }
            switch (id2) {
            case 0x01:
                msg = new RequestManorList();
                break;
            case 0x02:
                msg = new RequestProcureCropList();
                break;
            case 0x03:
                msg = new RequestSetSeed();
                break;
            case 0x04:
                msg = new RequestSetCrop();
                break;
            case 0x05:
                msg = new RequestWriteHeroWords();
                break;
            case 0x06:
                msg = new RequestExAskJoinMPCC();
                break;
            case 0x07:
                msg = new RequestExAcceptJoinMPCC();
                break;
            case 0x08:
                msg = new RequestExOustFromMPCC();
                break;
            case 0x09:
                msg = new RequestOustFromPartyRoom();
                break;
            case 0x0a:
                msg = new RequestDismissPartyRoom();
                break;
            case 0x0b:
                msg = new RequestWithdrawPartyRoom();
                break;
            case 0x0c:
                msg = new RequestChangePartyLeader();
                break;
            case 0x0d:
                msg = new RequestAutoSoulShot();
                break;
            case 0x0e:
                msg = new RequestExEnchantSkillInfo();
                break;
            case 0x0f:
                msg = new RequestExEnchantSkill();
                break;
            case 0x10:
                msg = new RequestExPledgeCrestLarge();
                break;
            case 0x11:
                msg = new RequestExSetPledgeCrestLarge();
                break;
            case 0x12:
                msg = new RequestPledgeSetAcademyMaster();
                break;
            case 0x13:
                msg = new RequestPledgePowerGradeList();
                break;
            case 0x14:
                msg = new RequestPledgeMemberPowerInfo();
                break;
            case 0x15:
                msg = new RequestPledgeSetMemberPowerGrade();
                break;
            case 0x16:
                msg = new RequestPledgeMemberInfo();
                break;
            case 0x17:
                msg = new RequestPledgeWarList();
                break;
            case 0x18:
                msg = new RequestExFishRanking();
                break;
            case 0x19:
                msg = new RequestPCCafeCouponUse();
                break;
            case 0x1b:
                msg = new RequestDuelStart();
                break;
            case 0x1c:
                msg = new RequestDuelAnswerStart();
                break;
            case 0x1e:
                msg = new RequestExRqItemLink();
                break;
            case 0x21:
                msg = new RequestKeyMapping();
                break;
            case 0x22:
                // TODO implement me (just disabling warnings for this packet)
                break;
            case 0x23:
                msg = new RequestExRemoveItemAttribute();
                break;
            case 0x24:
                msg = new RequestSaveInventoryOrder();
                break;
            case 0x25:
                msg = new RequestExitPartyMatchingWaitingRoom();
                break;
            case 0x26:
                msg = new RequestConfirmTargetItem();
                break;
            case 0x27:
                msg = new RequestConfirmRefinerItem();
                break;
            case 0x28:
                msg = new RequestConfirmGemStone();
                break;
            case 0x29:
                msg = new RequestOlympiadObserverEnd();
                break;
            case 0x2a:
                msg = new RequestCursedWeaponList();
                break;
            case 0x2b:
                msg = new RequestCursedWeaponLocation();
                break;
            case 0x2c:
                msg = new RequestPledgeReorganizeMember();
                break;
            case 0x2e:
                msg = new RequestExMPCCShowPartyMembersInfo();
                break;
            case 0x2f:
                msg = new RequestOlympiadMatchList();
                break;
            case 0x30:
                msg = new RequestAskJoinPartyRoom();
                break;
            case 0x31:
                msg = new AnswerJoinPartyRoom();
                break;
            case 0x32:
                msg = new RequestListPartyMatchingWaitingRoom();
                break;
            case 0x33:
                msg = new RequestExEnchantSkillSafe();
                break;
            case 0x34:
                msg = new RequestExEnchantSkillUntrain();
                break;
            case 0x35:
                msg = new RequestExEnchantSkillRouteChange();
                break;
            case 0x36:
                msg = new ExGetOnAirShip();
                break;
            case 0x38:
                msg = new RequestExEnchantItemAttribute();
                break;
            case 0x3f:
                msg = new RequestAllCastleInfo();
                break;
            case 0x40:
                msg = new RequestAllFortressInfo();
                break;
            case 0x41:
                msg = new RequestAllAgitInfo();
                break;
            case 0x42:
                msg = new RequestFortressSiegeInfo();
                break;
            case 0x43:
                msg = new RequestGetBossRecord();
                break;
            case 0x44:
                msg = new RequestRefine();
                break;
            case 0x45:
                msg = new RequestConfirmCancelItem();
                break;
            case 0x46:
                msg = new RequestRefineCancel();
                break;
            case 0x47:
                msg = new RequestExMagicSkillUseGround();
                break;
            case 0x48:
                msg = new RequestDuelSurrender();
                break;
            case 0x49:
                msg = new RequestExEnchantSkillInfoDetail();
                break;
            case 0x4b:
                msg = new RequestFortressMapInfo();
                break;
            case 0x4d:
                msg = new SetPrivateStoreWholeMsg();
                break;
            case 0x4e:
                msg = new RequestDispel();
                break;
            case 0x4f:
                msg = new RequestExTryToPutEnchantTargetItem();
                break;
            case 0x50:
                msg = new RequestExTryToPutEnchantSupportItem();
                break;
            case 0x51:
                msg = new RequestExCancelEnchantItem();
                break;
            case 0x52:
                msg = new RequestChangeNicknameColor();
                break;
            case 0x53:
                msg = new RequestResetNickname();
                break;
            case 0x54:
                // TODO: implement me (just disabling warnings for this packet)
                break;
            case 0x58:
                // TODO: implement me (just disabling warnings for this packet)
                break;
            default:
                printDebug(buf, client, opcode, id2);
                break;
            }
            break;
        /*case 0xee:
          msg = new RequestChangePartyLeader(data, _client);
          break;*/
        default:
            printDebug(buf, client, opcode);
            break;
        }
        break;
    }
    return msg;
}