Thread: send PM to player from plain text.

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 send PM to player from plain text. 
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    I use this for my GUI.

    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.



    Have fun
    Reply With Quote  
     

  2. #2  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    5,031
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    coool

    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Just a theory, but maybe it's indented weird because you're using spaces AND tabs?
    Reply With Quote  
     

  4. #4  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    Quote Originally Posted by filth jr View Post
    Just a theory, but maybe it's indented weird because you're using spaces AND tabs?
    It has something to do with what happens when you put something from Notepad++ into Netbeans.

    Maybe Netbeans replaces tabs with spaces or something but I'd never intentionally indent with spaces.
    Reply With Quote  
     

  5. #5  
    Registered Member Paketa's Avatar
    Join Date
    Oct 2007
    Posts
    2,681
    Thanks given
    17
    Thanks received
    82
    Rep Power
    680
    This is really good. Outstanding work Illuminate!
    Reply With Quote  
     

  6. #6  
    Registered Member
    Knova's Avatar
    Join Date
    Aug 2007
    Age
    33
    Posts
    677
    Thanks given
    0
    Thanks received
    9
    Rep Power
    344
    now that is awesome
    I AM KITE! Hope you like my programming!
    Reply With Quote  
     

  7. #7  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    Fucking amazing.
    How does one go about turning the PM chat of a user into read-able text, as Im trying to create a chat-monitor for the GUI and I cant seem to monitor private chat.
    Reply With Quote  
     

  8. #8  
    Registered Member
    G R A P E D's Avatar
    Join Date
    Feb 2009
    Age
    30
    Posts
    681
    Thanks given
    26
    Thanks received
    4
    Rep Power
    334
    Pretty awesome, Good Job.

    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Nov 2008
    Posts
    2,180
    Thanks given
    148
    Thanks received
    99
    Rep Power
    2004
    Roger did this?
    Reply With Quote  
     

  10. #10  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    Quote Originally Posted by bloodargon View Post
    Fucking amazing.
    How does one go about turning the PM chat of a user into read-able text, as Im trying to create a chat-monitor for the GUI and I cant seem to monitor private chat.
    Put this at the end of the chat packet handling. I think the id is 3.

    Code:
    char decodeBuf[] = new char[4096];
    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', '$', '%', '"', '[',
    	']'
    };
    int idx = 0, highNibble = -1;
    for (int i = 0; i < chatTextSize * 2; i++)
    {
    	int val = chatText[i / 2] >> (4 - 4 * (i % 2)) & 0xf;
    	if (highNibble == -1)
    	{
    		if (val < 13) 
    			decodeBuf[idx++] = xlateTable[val];
    		else 
    			highNibble = val;
    	}
    	else
    	{
    		decodeBuf[idx++] = xlateTable[((highNibble << 4) + val) - 195];
    		highNibble = -1;
    	}
    }
    String chatInPlainText = new String(decodeBuf, 0, idx);
    Quote Originally Posted by Demetri View Post
    Roger did this?
    Link or it didn't happen
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •