summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-02 02:02:07 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-02 02:02:07 +0000
commit3413f527f0945d08dc9102e75b2d9630d6855ed1 (patch)
treeeaeb0afa18faa9c31694051c783febd17bc506e4
parent287cb92158ee9eeba5eac6edea7d830777810beb (diff)
encode/decode smileys
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@237 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r--MySpace/formatting.cpp75
-rw-r--r--MySpace/formatting.h4
-rw-r--r--MySpace/proto.cpp1
-rw-r--r--MySpace/server_con.cpp1
-rw-r--r--MySpace/version.h2
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, "&quot;", size - out); out += 6; break;
case '&': in++; strncpy(tmp + out, "&amp;", 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, "<i n=\"%s\"/>", 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, "<i n=\"%s\"/>", 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, "<i n='%s\'/>", 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, "<p><f f='Times' h='16'><c v='black'><b v='white'>%s</b></c></f></p>", 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