Code:
public void sendPM(String from, String message)
{
long l = 0L;
for (int i = 0; i < from.length() && i < 12; i++)
{
char c = from.charAt(i);
l *= 37L;
if (c >= 'A' && c <= 'Z') l += (1 + c) - 65;
else if (c >= 'a' && c <= 'z') l += (1 + c) - 97;
else if (c >= '0' && c <= '9') l += (27 + c) - 48;
}
while (l % 37L == 0L && l != 0L) l /= 37L;
outStream.createFrame(221);
outStream.writeByte(2);
outStream.createFrame(50);
outStream.writeQWord(l);
outStream.writeByte(9);
outStream.createFrameVarSize(196);
outStream.writeQWord(l);
outStream.writeDWord(chatIndex);//The int that keeps track of clients private chat index
chatIndex++;//The int that keeps track of clients private chat index
outStream.writeByte(3);//Rights - 3 is admin
packedData = new byte[256];
char xlateTable[] = {
' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r',
'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p',
'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', ' ', '!', '?',
'.', ',', ':', ';', '(', ')', '-', '&', '*', '\\',
'\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[',
']'
};
if (message.length() > 80)
message = message.substring(0, 80);
message = message.toLowerCase();
int carryOverNibble = -1;
int ofs = 0;
for (int idx = 0; idx < message.length(); idx++) {
char c = message.charAt(idx);
int tableIdx = 0;
for (int i = 0; i < xlateTable.length; i++) {
if (c == xlateTable[i]) {
tableIdx = i;
break;
}
}
if (tableIdx > 12)
tableIdx += 195;
if (carryOverNibble == -1) {
if (tableIdx < 13)
carryOverNibble = tableIdx;
else
packedData[ofs++] = (byte) (tableIdx);
} else if (tableIdx < 13) {
packedData[ofs++] = (byte) ((carryOverNibble << 4) + tableIdx);
carryOverNibble = -1;
} else {
packedData[ofs++] = (byte) ((carryOverNibble << 4) + (tableIdx >> 4));
carryOverNibble = tableIdx & 0xf;
}
}
if (carryOverNibble != -1)
packedData[ofs++] = (byte) (carryOverNibble << 4);
outStream.writeBytes(packedData, message.getBytes().length, 0);
outStream.endFrameVarSize();
}
Not sure why it's indented weird. Sorry.