⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evautil.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2004 by yunfan                                          * *   yunfan_zg@163.com                                                     * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include "evautil.h"#include <string>#ifdef _WIN32#include <winsock.h>#else#include <arpa/inet.h>#endif#include "md5.h"const char EvaUtil::smileyMap[QQ_SMILEY_AMOUNT] = {	0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,	0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x73,	0x74,0x75,0x76,0x77,0x8a,0x8b,0x8c,0x8d,	0x8e,0x8f,0x78,0x79,0x7a,0x7b,0x90,0x91,	0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,	0x59,0x5a,0x5c,0x58,0x57,0x55,0x7c,0x7d,	0x7e,0x7f,0x9a,0x9b,0x60,0x67,0x9c,0x9d,	0x9e,0x5e,0x9f,0x89,0x80,0x81,0x82,0x62,	0x63,0x64,0x65,0x66,0x83,0x68,0x84,0x85,	0x86,0x87,0x6b,0x6e,0x6f,0x70,0x88,0xa0,	0x50,0x51,0x52,0x53,0x54,0x56,0x5b,0x5d,	0x5f,0x61,0x69,0x6a,0x6c,0x6d,0x71,0x72,};char EvaUtil::md5Buf[KEY_LENGTH];EvaUtil::textMap EvaUtil::map[QQ_SMILEY_AMOUNT];EvaUtil::EvaUtil(){	initMap();}char *EvaUtil::doMd5(char *in, int len){	md5_state_t ctx;	md5_init(&ctx);	md5_append(&ctx, (md5_byte_t *)in, len);	md5_finish(&ctx, (md5_byte_t *)md5Buf);	return md5Buf;}char *EvaUtil::doMd5Md5(char *in, int len){	doMd5(in, len);	doMd5(md5Buf, KEY_LENGTH);	return md5Buf;}std::string EvaUtil::smileyToText(const char smileyCode){	int i = smileyToFileIndex(smileyCode);	std::string text = map[i].py;	return text;}char EvaUtil::textToSmiley(const std::string &textTag){	std::string strEn, strPy;	for(int i=0; i<QQ_SMILEY_AMOUNT; i++){		strEn = map[i].en;		strPy = map[i].py;		if(strEn == textTag || strPy == textTag){			return smileyMap[i];		}	}	return 0;}int EvaUtil::textToFileIndex(const std::string &textTag){	char s = textToSmiley(textTag);	return smileyToFileIndex(s);}int EvaUtil::smileyToFileIndex( const char smileyCode){	for(int i=0; i<QQ_SMILEY_AMOUNT; i++){		if(smileyMap[i]==smileyCode)			return i;	}        return -1;}std::string EvaUtil::fileIndexToText( const int fileIndex){	if(fileIndex<0 || fileIndex > 95 ) return "";	return map[fileIndex].py;}std::string EvaUtil::convertToSend( const std::string & text){	std::string converted = "";	int offset=0;	char smileyTag = 0x14;	char customTag = 0x15;	bool isFirst32 = true;	std::string code32FileTag = "";	char seperator32_1 = 0x13;	char seperator32_2 = 0x4c;	for(uint i=0; i< text.length(); i++){		if(text[i] == '/'){			offset = i;			while(text[offset] != 0x00 && text[++offset]!=' ');			if((offset - i)<8){				char code = textToSmiley(text.substr(i,offset-i));				if(code){					converted += smileyTag;					converted += code;					i=offset;					continue;				}			}			converted+=text[i];			continue;		}else{			if(text[i] == '['){				std::string zdyTag = text.substr(i, 5);				if(zdyTag == "[ZDY]"){					offset = text.find("[/ZDY]", i);					std::string zdyType = text.substr(i+6, 2);					zdyTag = text.substr(i+5+4, offset-i-14);					std::string sendFormat;					sendFormat += customTag;					if(zdyType == "32"){						if(isFirst32){							code32FileTag = zdyTag.substr(0, zdyTag.length() - 7);							code32FileTag += seperator32_1;							code32FileTag += seperator32_2;							isFirst32 = false;						}						sendFormat += "2"; // 0x32						sendFormat += zdyTag.substr(zdyTag.length() - 2, 2);						sendFormat += "999999";					} else	if(zdyType == "36"){						sendFormat += "6"; // note: at the moment, we only use type 6						int len = zdyTag.length() + 5; // the len includes tag(1) and type(1) and itself(3)						char *strLen = new char[4];						sprintf(strLen, "%3d", len);						sendFormat += strLen;						delete strLen;						sendFormat += zdyTag;					}					converted += sendFormat;//printf("sendFormat:%s\n",sendFormat.c_str());					i += (offset - i + 5);					continue;				}			}		}		converted+=text[i];	}	if(!isFirst32)		converted = code32FileTag + converted; 	return converted;}std::string EvaUtil::convertToSend(const std::string &text, bool *hasImage){	std::string converted = "";	int offset=0;	char smileyTag = 0x14;	char customTag = 0x15;	bool isFirst32 = true;	std::string code32FileTag = "";	char seperator32_1 = 0x13;	char seperator32_2 = 0x4c;	for(uint i=0; i< text.length(); i++){		if(text[i] == '/'){			offset = i;			while(text[offset] != 0x00 && text[++offset]!=' ');			if((offset - i)<8){				char code = textToSmiley(text.substr(i,offset-i));				if(code){					converted += smileyTag;					converted += code;					i=offset;					continue;				}			}			converted+=text[i];			continue;		}else{			if(text[i] == '['){				std::string zdyTag = text.substr(i, 5);				if(zdyTag == "[ZDY]"){					offset = text.find("[/ZDY]", i);					std::string zdyType = text.substr(i+6, 2);					zdyTag = text.substr(i+5+4, offset-i-14);					std::string sendFormat;					sendFormat += customTag;					if(zdyType == "32"){						if(isFirst32){							code32FileTag = zdyTag.substr(0, zdyTag.length() - 7);							code32FileTag += seperator32_1;							code32FileTag += seperator32_2;							isFirst32 = false;						}						sendFormat += "2"; // 0x32						sendFormat += zdyTag.substr(zdyTag.length() - 2, 2);						sendFormat += "999999";					} else	if(zdyType == "36"){						sendFormat += "6"; // note: at the moment, we only use type 6						int len = zdyTag.length() + 5; // the len includes tag(1) and type(1) and itself(3)						char *strLen = new char[4];						sprintf(strLen, "%3d", len);						sendFormat += strLen;						delete strLen;						sendFormat += zdyTag;					}					converted += sendFormat;					i += (offset - i + 5);					continue;				}			}		}		converted+=text[i];	}	if(!isFirst32){		converted = code32FileTag + converted; 		*hasImage = true;	} else		*hasImage = false;	return converted;}void EvaUtil::initMap(){	strcpy(map[0].en,"/:o"); strcpy(map[0].py, "/jy");	strcpy(map[1].en, "/:~"); strcpy(map[1].py, "/pz");	strcpy(map[2].en, "/:*"); strcpy(map[2].py, "/se");	strcpy(map[3].en, "/:|"); strcpy(map[3].py, "/fd");	strcpy(map[4].en, "/8-)"); strcpy(map[4].py, "/dy");	strcpy(map[5].en, "/:<"); strcpy(map[5].py, "/ll");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -