/***************************************************************************
 *   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.             *
 ***************************************************************************/
 
#ifndef LIBEVADEFINES_H
#define LIBEVADEFINES_H

/** add a type define for uint in case that some platform dose not has type uint */
typedef unsigned int uint;

/** Visual Studio .NET 2002/2003 Additional Definitions */
#ifdef WIN32
#pragma warning(disable: 4309 4800)
typedef unsigned char uint8_t;
#include <malloc.h>
#endif

/**
 * define all constants for eva use */
/** bytes from 16 to 51 in login request */ 
static const unsigned char login_16_51[]= {
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x4c, 0x28, 0xeb, 0xaa, 0xe9, 
			0x7f, 0x2a, 0x7c, 0xf9, 0xa9, 0x0f, 0x84, 0xdd, 
			0xbb, 0xb2, 0x0f, 0x01
			};
/** bytes from 53 to  68,  used in login request  */
static const unsigned char login_53_68 []= {
			0x43, 0xc3, 0x80, 0x19, 0x46, 0x05, 0x3e, 0x4b, 
			0x91, 0x60, 0x5b, 0xf8, 0x17, 0xd7, 0xf3, 0x5b
			};      
/** unknown bytes in login request  */
static const unsigned char login_94_193 []= {
			0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
			0x00, 0x00, 0x00, 0x00
			};

/**  eva, URL of applying free qq acount */
static const char QQ_APPLY_FREE_NUMBER_URL[] = "http://freeqq2.qq.com/1.shtml";

/** eva system message types */
const unsigned short SYSTEM_MESSAGE_NORMAL = 0x0001;

/** udp  */
static const int QQ_LOGIN_UDP = 0;
/** tcp */
static const int QQ_LOGIN_TCP = 1;

/** QQ UDP packet header length*/
const int QQ_UDP_HEADER_LENGTH = 7;
/** QQ TCP packet header length */
const int QQ_TCP_HEADER_LENGTH = 9;
/** QQ packet tail length*/
const int QQ_TAIL_LENGTH = 1;

/**  the number of send times*/ 
const int QQ_ACK_PACKET_SEND_TIME = 4;


/** QQ packet maximum size*/
const int MAX_PACKET_SIZE = 65535;
/** the maximum bytes to send at once*/
const int MAX_SEND_IM_SIZE = 400;
/**  QQ key length*/
const int QQ_KEY_LENGTH = 16;
/** QQ login data  length */
const int QQ_LOGIN_DATA_LENGTH = 416;

/** QQ default encoding */
const short QQ_IM_ENCODING_GB = 0x8602;

/** packet queue time out */
const long QQ_SENDQUEUE_TIMEOUT = 5000;
/** the times of maximum re-send a packet */
const int QQ_RESEND_MAX = 5;
/** Keep Alive time interval   unit: ms */
const unsigned long QQ_KEEP_ALIVE_INTERVAL = 60000;

const int QQ_MAX_GROUP_NAME_BYTE = 16;
const int QQ_NAME_LENGTH_MAX = 250;
const int QQ_MSG_IM_MAX = 1500;
const int QQ_CONTACT_FIELDS = 37;
const int QQ_REMARK_FIELDS = 7;

/**  client GB QQ2000c build 630 */
const short QQ_CLIENT_062E = 0x062E;
/** client En QQ2000c build 305 */
const short QQ_CLIENT_072E = 0x072E;
/** client En QQ2000c build 630 */
const short QQ_CLIENT_0801 = 0x0801;
/** client Gb QQ2003c build 0808 */
const short QQ_CLIENT_0A1D = 0x0A1D;
/** client Gb QQ2003c build 0925 */
const short QQ_CLIENT_0B07 = 0x0B07;
/** client GB QQ2003iii build 0117 */
const short QQ_CLIENT_0B2F = 0x0B2f;
/** GB QQ2003iii build 0304 (offical release) */
const short QQ_CLIENT_0B35 = 0x0B35;
/** QQ20003  */
const short QQ_CLIENT_0B37 = 0x0B37;
/** QQ2004 */
const short QQ_CLIENT_0C0B = 0x0C0B;
/** QQ2004 preview*/
const short QQ_CLIENT_0C0D = 0x0C0D;
/** QQ2004 */
const short QQ_CLIENT_0C21 = 0x0C21;
/** QQ2004II */
const short QQ_CLIENT_0C49 = 0x0C49;
/** QQ2005 beta1 */
const short QQ_CLIENT_0D05 = 0x0D05;
/** QQ2005 beta2 */
const short QQ_CLIENT_0D51 = 0x0D51;


/** QQ server  number*/
const short QQ_SERVER_0100 = 0x0100;
/** QQ Token server number*/
const short QQ_SERVER_0000 = 0x0000;

/**  default client version*/
const short QQ_CLIENT_VERSION = 0x0D51; //QQ_CLIENT_0D05;
/**  qq header tag*/
const unsigned char QQ_PACKET_TAG = 0x02;
/** QQ tail byte*/
const unsigned char QQ_PACKET_TAIL = 0x03;

const unsigned char QQ_LOGIN_MODE_NORMAL = 0x0A;
const unsigned char QQ_LOGIN_MODE_INVISIBLE = 0x28;

const unsigned char QQ_FRIEND_GENDER_GG = 0x0;
const unsigned char QQ_FRIEND_GENDER_MM = 0x1;

const unsigned char QQ_FRIEND_GENDER_UNKNOWN = 0xFF;

const unsigned char QQ_FRIEND_FLAG_QQ_MEMBER = 0x01;
const unsigned char QQ_FRIEND_FLAG_MOBILE = 0x10;
const unsigned char QQ_FRIEND_FLAG_BIND_MOBILE = 0x20;

const unsigned char QQ_FRIEND_STATUS_ONLINE = 10;
const unsigned char QQ_FRIEND_STATUS_OFFLINE = 20;
const unsigned char QQ_FRIEND_STATUS_LEAVE = 30;
const unsigned char QQ_FRIEND_STATUS_INVISIBLE = 40;

const int QQ_MISC_STATUS_HAVING_VIDEO = 0x00000001;

const unsigned char QQ_REQUEST_LOGIN_TOKEN_REPLY_OK = 0x00;
const unsigned char QQ_LOGIN_REPLY_OK = 0x00;
const unsigned char QQ_LOGIN_REPLY_REDIRECT = 0x01;
const unsigned char QQ_LOGIN_REPLY_PWD_ERROR = 0x05;
const unsigned char QQ_LOGIN_REPLY_MISC_ERROR = 0x06;

const unsigned char QQ_UPLOAD_GROUP_FRIEND_OK = 0x00;
const unsigned char QQ_UPLOAD_FRIEND_REMARK_OK = 0x00;
const unsigned char QQ_CHANGE_STATUS_REPLY_OK = 0x30;

const unsigned char QQ_SEND_IM_REPLY_OK = 0x00;

const unsigned char QQ_ADD_FRIEND_AUTH_REPLY_OK = 0x30;
const unsigned char QQ_DELETE_FRIEND_REPLY_OK = 0x00;
const unsigned char QQ_DELETE_ME_REPLY_OK = 0x00;

const unsigned char QQ_REQUEST_KEY_REPLY_OK = 0x00;

const short QQ_FRIEND_LIST_POSITION_START = 0x0000;
const short QQ_FRIEND_LIST_POSITION_END = 0xFFFF;
const char QQ_FRIEND_ONLINE_LIST_POSITION_START = 0x00;
const char QQ_FRIEND_ONLINE_LIST_POSITION_END = 0xFF; 
const unsigned char QQ_FRIEND_LIST_UNSORTED = 0;
const unsigned char QQ_FRIEND_LIST_SORTED = 1;


/* QQ commands */
const short QQ_CMD_LOGOUT = 0x0001;
const short QQ_CMD_KEEP_ALIVE = 0x0002;
const short QQ_CMD_MODIFY_INFO = 0x0004;
const short QQ_CMD_SEARCH_USER = 0x0005;
const short QQ_CMD_GET_USER_INFO = 0x0006;
const short QQ_CMD_ADD_FRIEND = 0x0009;
const short QQ_CMD_DELETE_FRIEND = 0x000A;
const short QQ_CMD_ADD_FRIEND_AUTH = 0x000B;
const short QQ_CMD_CHANGE_STATUS = 0x000D;
const short QQ_CMD_ACK_SYS_MSG = 0x0012;
const short QQ_CMD_SEND_IM = 0x0016;
const short QQ_CMD_RECV_IM = 0x0017;
const short QQ_CMD_DELETE_ME = 0x001C;
const short QQ_CMD_REQUEST_KEY = 0x001D;
const short QQ_CMD_CELL_PHONE_1 = 0x0021;
const short QQ_CMD_LOGIN = 0x0022;
const short QQ_CMD_GET_FRIEND_LIST = 0x0026;
const short QQ_CMD_GET_FRIEND_ONLINE = 0x0027;
const short QQ_CMD_CELL_PHONE_2 = 0x0029;
const short QQ_CMD_QUN_CMD = 0x0030;
const short QQ_CMD_TEST = 0x0031;
const short QQ_CMD_GROUP_NAME_OP = 0x003C;
const short QQ_CMD_UPLOAD_GROUP_FRIEND = 0x003D;
const short QQ_CMD_FRIEND_REMARK_OP = 0x003E;
const short QQ_CMD_DOWNLOAD_GROUP_FRIEND = 0x0058;
const short QQ_CMD_GET_LEVEL = 0x005C;
const short QQ_CMD_REQUEST_LOGIN_TOKEN = 0x0062;
const short QQ_CMD_REQUEST_EXTRA_INFORMATION = 0x0065;
const short QQ_CMD_SIGNATURE_OP = 0x0067;
const short QQ_CMD_RECV_MSG_SYS = 0x0080;
const short QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS = 0x0081;

const unsigned char QQ_REQUEST_UNKNOWN_KEY = 0x03;
const unsigned char QQ_REQUEST_FILE_AGENT_KEY = 0x04;

const unsigned char QQ_IM_NORMAL_REPLY = 0x01;
const unsigned char QQ_IM_AUTO_REPLY = 0x02;

/** flags of QQ_CMD_REQUEST_EXTRA_INFORMATION return */
const unsigned short QQ_EXTAR_INFO_PAL       = 0x0004;  // QQ friends center flag
const unsigned short QQ_EXTAR_INFO_USER_HEAD = 0x0010;  // QQ customized face flag, QQ calls them user head, because all pictures stored in UserHead directory
const unsigned short QQ_EXTAR_INFO_ALBUM     = 0x0100;  // QQ ablum flag
const unsigned short QQ_EXTAR_INFO_TANG      = 0x0800;  // QQ tang flag, is QQ tang a sort of game? not sure what it is.
const unsigned short QQ_EXTAR_INFO_SIGNATURE = 0x4000;  // QQ personal signature flag

/** sub-command of QQ_CMD_REQUEST_SIGNATURE */
const unsigned char QQ_SIGNATURE_MODIFY = 0x01;
const unsigned char QQ_SIGNATURE_DELETE = 0x02;
const unsigned char QQ_SIGNATURE_REQUEST = 0x03;

/*  sub-command of Qun */
const unsigned char QQ_QUN_CMD_CREATE_QUN          = 0x01;
const unsigned char QQ_QUN_CMD_MODIFY_MEMBER       = 0x02;
const unsigned char QQ_QUN_CMD_MODIFY_QUN_INFO     = 0x03;
const unsigned char QQ_QUN_CMD_GET_QUN_INFO        = 0x04;
const unsigned char QQ_QUN_CMD_ACTIVATE_QUN        = 0x05;
const unsigned char QQ_QUN_CMD_SEARCH_QUN          = 0x06;
const unsigned char QQ_QUN_CMD_JOIN_QUN            = 0x07;
const unsigned char QQ_QUN_CMD_JOIN_QUN_AUTH       = 0x08;
const unsigned char QQ_QUN_CMD_EXIT_QUN            = 0x09;
const unsigned char QQ_QUN_CMD_SEND_IM             = 0x0A;
const unsigned char QQ_QUN_CMD_GET_ONLINE_MEMBER   = 0x0B;
const unsigned char QQ_QUN_CMD_GET_MEMBER_INFO     = 0x0C;
const unsigned char QQ_QUN_CMD_MODIFY_CARD         = 0x0E;
const unsigned char QQ_QUN_CMD_REQUEST_CARD        = 0x10;
const unsigned char QQ_QUN_CMD_SEND_IM_EX          = 0x1A;
const unsigned char QQ_QUN_CMD_ADMIN               = 0x1B;
const unsigned char QQ_QUN_CMD_TRANSFER            = 0x1C;
const unsigned char QQ_QUN_CMD_CREATE_TEMP_QUN     = 0x30;
const unsigned char QQ_QUN_CMD_MODIFY_TEMP_QUN_MEMBER    = 0x31;
const unsigned char QQ_QUN_CMD_EXIT_TEMP_QUN       = 0x32;
const unsigned char QQ_QUN_CMD_GET_TEMP_QUN_INFO   = 0x33;
const unsigned char QQ_QUN_CMD_SEND_TEMP_QUN_IM    = 0x35;
const unsigned char QQ_QUN_CMD_GET_TEMP_QUN_MEMBERS      = 0x37;
const unsigned char QQ_QUN_CMD_REPLY_OK            = 0x00;
const unsigned char QQ_QUN_CMD_REPLY_NO_SUCH_QUN   = 0x02;
const unsigned char QQ_QUN_CMD_REPLY_TEMP_QUN_REMOVED    = 0x03;
const unsigned char QQ_QUN_CMD_REPLY_NOT_TEMP_QUN_MEMBER = 0x04;
const unsigned char QQ_QUN_CMD_REPLY_NOT_QUN_MEMBER      = 0x0a;
const unsigned char QQ_QUN_TYPE_PERMANENT          = 0x01;
const unsigned char QQ_TEMP_QUN_TYPE_MULTI_TALK    = 0x01;
const unsigned char QQ_TEMP_QUN_TYPE_DISCUSSION_GROUP    = 0x02;
const unsigned char QQ_QUN_MEMBER_ADD              = 0x01;
const unsigned char QQ_QUN_MEMBER_REMOVE           = 0x02;
const unsigned char QQ_QUN_NO_AUTH                 = 0x01;
const unsigned char QQ_QUN_NEED_AUTH               = 0x02;
const unsigned char QQ_QUN_NO_ADD                  = 0x03;
const unsigned char QQ_QUN_AUTH_REQUEST            = 0x01;
const unsigned char QQ_QUN_AUTH_APPROVE            = 0x02;
const unsigned char QQ_QUN_AUTH_REJECT             = 0x03;
const unsigned char QQ_QUN_JOIN_OK                 = 0x01;
const unsigned char QQ_QUN_JOIN_NEED_AUTH          = 0x02;
const unsigned char QQ_QUN_JOIN_DENIED             = 0x03;
const unsigned char QQ_SEARCH_QUN_BY_ID            = 0x01;
const unsigned char QQ_SEARCH_DEMO_QUN             = 0x02;
const unsigned char QQ_QUN_UNSET_ADMIN            = 0x00;
const unsigned char QQ_QUN_SET_ADMIN               = 0x01;


/* group operation commands */
const unsigned char QQ_UPLOAD_GROUP_NAME = 0x2;
const unsigned char QQ_DOWNLOAD_GROUP_NAME = 0x1;

/* remark operation commands */
const unsigned char QQ_UPLOAD_FRIEND_REMARK = 0x1;
const unsigned char QQ_DOWNLOAD_FRIEND_REMARK = 0x3;

/* used in download grouped friends */
const unsigned char QQ_ID_IS_FRIEND = 0x1;
const unsigned char QQ_ID_IS_QUN = 0x4;

/** types of received message */
const short QQ_RECV_IM_TO_BUDDY = 0x0009;
const short QQ_RECV_IM_TO_UNKNOWN = 0x000A;
/** message from Qun */
const short QQ_RECV_IM_QUN_IM_TEMP = 0x001F; // this means another member of a Qun send a message to you only
const short QQ_RECV_IM_UNKNOWN_QUN_IM = 0x0020;
const short QQ_RECV_IM_ADDED_TO_QUN = 0x0021;
const short QQ_RECV_IM_DELETED_FROM_QUN = 0x0022; // kicked out from a Qun
const short QQ_RECV_IM_REQUEST_JOIN_QUN = 0x0023;
const short QQ_RECV_IM_APPROVE_JOIN_QUN = 0x0024;
const short QQ_RECV_IM_REJECT_JOIN_QUN = 0x0025;
const short QQ_RECV_IM_CREATE_QUN = 0x0026;
const short QQ_RECV_IM_TEMP_QUN_IM = 0x002A;
const short QQ_RECV_IM_QUN_IM = 0x002B;
const short QQ_RECV_IM_SYS_MESSAGE = 0x0030;
const short QQ_RECV_IM_SIGNATURE_CHANGED = 0x0041;

/** system message */
const unsigned char QQ_RECV_IM_KICK_OUT = 0x01;

/* sub types of QQ_RECV_IM_TO_BUDDY */
const short QQ_IM_NORMAL_TEXT = 0x000B;
const short QQ_IM_TCP_REQUEST = 0x0001;
const short QQ_IM_ACCEPT_TCP_REQUEST = 0x0003;
const short QQ_IM_REJECT_TCP_REQUEST = 0x0005;
const short QQ_IM_UDP_REQUEST = 0x0035;
const short QQ_IM_ACCEPT_UDP_REQUEST = 0x0037;
const short QQ_IM_REJECT_UDP_REQUEST = 0x0039;
const short QQ_IM_NOTIFY_IP = 0x003B;
const short QQ_IM_ARE_YOU_BEHIND_FIREWALL = 0x003F;
const short QQ_IM_ARE_YOU_BEHIND_PROXY = 0x0041;
const short QQ_IM_YES_I_AM_BEHIND_PROXY = 0x0042;
const short QQ_IM_NOTIFY_FILE_AGENT_INFO = 0x004B;
const short QQ_IM_REQUEST_CANCELED = 0x0049;

/** Qun type */
const unsigned char QUN_TYPE_ADMIN = 1;
const unsigned char QUN_TYEP_SHAREHOLDER = 2;

/** authorization */
const unsigned char QQ_AUTH_NO_AUTH = 0;
const unsigned char QQ_AUTH_NEED_AUTH = 1;
const unsigned char QQ_AUTH_NO_ADD = 2;

const unsigned char QQ_MY_AUTH_APPROVE = 0x30;
const unsigned char QQ_MY_AUTH_REJECT = 0x31;
const unsigned char QQ_MY_AUTH_REQUEST = 0x32;

const int QQ_CONTACT_OPEN = 0;
const int QQ_CONTACT_ONLY_FRIENDS = 1;
const int QQ_CONTACT_CLOSE = 2;

const short QQ_MSG_SYS_BEING_ADDED = 1;
const short QQ_MSG_SYS_ADD_FRIEND_REQUEST = 2;
const short QQ_MSG_SYS_ADD_FRIEND_APPROVED = 3;
const short QQ_MSG_SYS_ADD_FRIEND_REJECTED = 4;
const short QQ_MSG_SYS_UPDATE_HINT = 9;

const unsigned char QQ_SEARCH_ALL = 0x31;
const unsigned char QQ_SEARCH_CUSTOM = 0x30;

#endif
