From 3413f527f0945d08dc9102e75b2d9630d6855ed1 Mon Sep 17 00:00:00 2001 From: sje Date: Mon, 2 Jul 2007 02:02:07 +0000 Subject: encode/decode smileys git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@237 4f64403b-2f21-0410-a795-97e2b3489a10 --- MySpace/formatting.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++-- MySpace/formatting.h | 4 +++ MySpace/proto.cpp | 1 + MySpace/server_con.cpp | 1 + MySpace/version.h | 2 +- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/MySpace/formatting.cpp b/MySpace/formatting.cpp index 4b8669a..891f75e 100644 --- a/MySpace/formatting.cpp +++ b/MySpace/formatting.cpp @@ -5,7 +5,7 @@ void entitize(char *buff, int size) { char *tmp = new char[size]; int in = 0, out = 0; - while(buff[in]) { + while(buff[in] && out < size) { switch(buff[in]) { case '\"': in++; strncpy(tmp + out, """, size - out); out += 6; break; case '&': in++; strncpy(tmp + out, "&", size - out); out += 5; break; @@ -48,7 +48,7 @@ void unentitize(char *buff) { void strip_tags(char *buff) { int in = 0, out = 0; while(buff[in]) { - if(buff[in] == '<') { + if(buff[in] == '<' && buff[in + 1] != 'i') { while(buff[in] && buff[in] != '>') in++; in++; } else @@ -57,3 +57,74 @@ void strip_tags(char *buff) { buff[out] = 0; } +char *words[25] = {"bigsmile", "growl", "mad", "scared", "tongue", "devil", "happy", "messed", "sidefrown", "upset", "frazzled", + "heart", "nerd", "sinister", "wink", "geek", "laugh", "oops", "smirk", "worried", "googles", "mohawk", "pirate", "straight", "kiss"}; +char *symbols[25] = {":D", ":E", "X(", ":O", ":p", "}:)", ":)", "X)", ":{", "B|", ":Z", + ":X", "Q)", ":B", ";-)", "B)", ":))", ":G", ":,", ":[", "%)", "-:", "P)", ":|", ":X"}; + +void encode_smileys(char *buff, int size) { + char *tmp = new char[size]; + + int in = 0, out = 0; + char sb[128]; + bool done; + int i, len, len_s; + while(buff[in] && out < size) { + done = false; + for(i = 0; i < 25; i++) { + len_s = strlen(symbols[i]); + if(strncmp(buff + in, symbols[i], len_s) == 0) { + mir_snprintf(sb, 128, "", words[i]); + len = strlen(sb); + strncpy(tmp + out, sb, size - out); + out += len; + in += len_s; + done = true; + break; + } + } + if(!done) tmp[out++] = buff[in++]; + } + tmp[out] = 0; + + strncpy(buff, tmp, size); + delete tmp; + buff[size - 1] = 0; +} + +void decode_smileys(char *buff) { + int in = 0, out = 0; + char sb[128]; + bool done; + int i, j, len, len_s; + while(buff[in]) { + if(buff[in] == '<') { + done = false; + for(i = 0; i < 25; i++) { + mir_snprintf(sb, 128, "", words[i]); + len = strlen(sb); + if(strncmp(buff + in, sb, len) == 0) { + len_s = strlen(symbols[i]); + strncpy(buff + out, symbols[i], len_s); + out += len_s; + in += len; + done = true; + break; + } + mir_snprintf(sb, 128, "", words[i]); + if(strncmp(buff + in, sb, len) == 0) { + len_s = strlen(symbols[i]); + strncpy(buff + out, symbols[i], len_s); + out += len_s; + in += len; + done = true; + break; + } + } + if(!done) buff[out++] = buff[in++]; + } else + buff[out++] = buff[in++]; + } + buff[out] = 0; +} + diff --git a/MySpace/formatting.h b/MySpace/formatting.h index 12b8cb5..b7342d2 100644 --- a/MySpace/formatting.h +++ b/MySpace/formatting.h @@ -3,6 +3,10 @@ void entitize(char *buff, int size); void unentitize(char *buff); + void strip_tags(char *buff); +void encode_smileys(char *buff, int size); +void decode_smileys(char *buff); + #endif diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp index 35ace9b..fbd45ed 100644 --- a/MySpace/proto.cpp +++ b/MySpace/proto.cpp @@ -159,6 +159,7 @@ int ProtoSendMessage(WPARAM wParam, LPARAM lParam) { msg_utf[MAX_MESSAGE_SIZE-1] = 0; entitize(msg_utf, MAX_MESSAGE_SIZE); + encode_smileys(msg_utf, MAX_MESSAGE_SIZE); mir_snprintf(msg_fmt, MAX_MESSAGE_SIZE, "

%s

", msg_utf); ClientNetMessage msg; diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index 87cb69e..5c3ef1c 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -433,6 +433,7 @@ void __cdecl ServerThreadFunc(void*) { char text[MAX_MESSAGE_SIZE]; if(msg.get_string("msg", text, MAX_MESSAGE_SIZE)) { strip_tags(text); + decode_smileys(text); unentitize(text); PROTORECVEVENT pre = {0}; diff --git a/MySpace/version.h b/MySpace/version.h index fca11da..fcb5ed7 100644 --- a/MySpace/version.h +++ b/MySpace/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 #define __RELEASE_NUM 1 -#define __BUILD_NUM 7 +#define __BUILD_NUM 8 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM #define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM -- cgit v1.2.3