Initial commit
This commit is contained in:
@@ -0,0 +1,581 @@
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "typedef.h"
|
||||
#include "debug.h"
|
||||
#include "MessageDef.h"
|
||||
|
||||
char zeroId[6] = {0};
|
||||
bool TruncUTF8( char* buf, int size )
|
||||
{
|
||||
if( strlen(buf) < size )
|
||||
return false;
|
||||
|
||||
unsigned char* bytes = (unsigned char*)buf;
|
||||
for( int i=size-2; i>=0; i-- ){
|
||||
if( bytes[i] <= 0x7F ){ //1字节
|
||||
bytes[i+1] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( bytes[i] >= 0xC0 && bytes[i] <= 0xDF ){ //2字节
|
||||
if( i+2 < size )
|
||||
bytes[i+2] = 0;
|
||||
else
|
||||
bytes[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( bytes[i] >= 0xE0 && bytes[i] <= 0xEF ){ //3字节
|
||||
if( i+3 < size )
|
||||
bytes[i+3] = 0;
|
||||
else
|
||||
bytes[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( bytes[i] >= 0xF0 && bytes[i] <= 0xF7 ){ //4字节
|
||||
if( i+4 < size )
|
||||
bytes[i+4] = 0;
|
||||
else
|
||||
bytes[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( bytes[i] >= 0xF8 && bytes[i] <= 0xFB ){ //5字节
|
||||
if( i+5 < size )
|
||||
bytes[i+5] = 0;
|
||||
else
|
||||
bytes[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( bytes[i] >= 0xFC && bytes[i] <= 0xFD ){ //6字节
|
||||
if( i+6 < size )
|
||||
bytes[i+6] = 0;
|
||||
else
|
||||
bytes[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ValidNetMessage(unsigned char* buf, int len)
|
||||
{
|
||||
return len>=10 && buf[0]==0x7E && buf[1]==0x6E;
|
||||
}
|
||||
|
||||
bool ReadNetMessage( unsigned char* pBuf, short nSize, TNETMESSAGE* pMsg )
|
||||
{
|
||||
if( !pMsg ){
|
||||
return false;
|
||||
}
|
||||
|
||||
// if( pBuf[0]!=0x7E || pBuf[1]!=0x6E ){
|
||||
// DebugPrint("读取网络消息失败:无效的消息头 %X %X\n", pBuf[0], pBuf[1]);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
USHORT nLength = USHORT(pBuf[2]<<8) + BYTE(pBuf[3]);
|
||||
USHORT nSequenceNum = USHORT(pBuf[4]<<8) + BYTE(pBuf[5]);
|
||||
USHORT eMessageType = USHORT(pBuf[6]<<8) + BYTE(pBuf[7]);
|
||||
USHORT iExtra = USHORT(pBuf[8]<<8) + BYTE(pBuf[9]);
|
||||
|
||||
if(iExtra < 0x0D00)
|
||||
nLength -= 8;
|
||||
|
||||
if( eMessageType<=e_InvalidMessage || eMessageType>=e_MessgeTypeEnd ){
|
||||
DebugPrint("读取网络消息失败:无效的消息类型 %d\n", eMessageType);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( nLength>MAX_MSG_LENGTH ){
|
||||
DebugPrint("读取网络消息失败:无效的消息体长度 len=%d size=%d\n", nLength, nSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
pMsg->nLength = nLength;
|
||||
pMsg->nSequenceNum = nSequenceNum;
|
||||
pMsg->eMessageType = eMessageType;
|
||||
pMsg->iExtra = iExtra;
|
||||
|
||||
int pos = 10;
|
||||
#ifdef _SERVER
|
||||
if(iExtra >= 0x0D00){ //MsgVer>=0x0D00之后的版本自带idDevice
|
||||
memcpy(pMsg->idDevice, pBuf+pos, 6);
|
||||
pos += 6;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( nSize<nLength+pos ){
|
||||
DebugPrint("读取网络消息失败:无效的消息体长度 len=%d size=%d\n", nLength, nSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( nLength>0 )
|
||||
memcpy( pMsg->byMessageBody, pBuf+pos, nLength );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteNetMessage( unsigned char* pBuf, short& nSize, TNETMESSAGE* pMsg )
|
||||
{
|
||||
if( nSize<pMsg->nLength+16 ){
|
||||
DebugPrint("写入网络消息失败:无效的缓冲区长度 len=%d size=%d\n", pMsg->nLength, nSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
short nLength = pMsg->nLength;
|
||||
#ifdef _SERVER
|
||||
if(!memcmp(pMsg->idDevice, zeroId, 6)){ //MsgVer<0x0D00 之前的版本
|
||||
nLength += 8;
|
||||
}
|
||||
#endif
|
||||
|
||||
pBuf[0] = 0x7E;
|
||||
pBuf[1] = 0x6E;
|
||||
pBuf[2] = (BYTE)(nLength >> 8);
|
||||
pBuf[3] = (BYTE)(nLength);
|
||||
pBuf[4] = (BYTE)(pMsg->nSequenceNum>>8);
|
||||
pBuf[5] = (BYTE)(pMsg->nSequenceNum);
|
||||
pBuf[6] = (BYTE)(pMsg->eMessageType>>8);
|
||||
pBuf[7] = (BYTE)(pMsg->eMessageType);
|
||||
pBuf[8] = (BYTE)(pMsg->iExtra>>8);
|
||||
pBuf[9] = (BYTE)(pMsg->iExtra);
|
||||
|
||||
int pos = 10;
|
||||
#ifndef _SERVER
|
||||
memcpy(pBuf+pos, pMsg->idDevice, 6); //客户端需发送idDevice
|
||||
pos += 6;
|
||||
#endif
|
||||
|
||||
if( pMsg->nLength>0 )
|
||||
memcpy( pBuf+pos, pMsg->byMessageBody, pMsg->nLength );
|
||||
|
||||
nSize = pMsg->nLength + pos;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int StyleDetail2Trans( TSTYLEDETAIL& detail, int &size, char *pData )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
size = 0;
|
||||
// fix part
|
||||
memcpy( pData, &detail, 20 );
|
||||
size += 20;
|
||||
|
||||
// var part
|
||||
int len;
|
||||
|
||||
if( TruncUTF8( detail.strAuthor, sizeof(detail.strAuthor) ) )
|
||||
ret = 1;
|
||||
|
||||
len = strlen( detail.strAuthor );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], detail.strAuthor, len );
|
||||
size += len;
|
||||
|
||||
if( TruncUTF8( detail.strStyleName, sizeof(detail.strStyleName) ) )
|
||||
ret = 2;
|
||||
|
||||
len = strlen( detail.strStyleName );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], detail.strStyleName, len );
|
||||
size += len;
|
||||
|
||||
if( TruncUTF8( detail.strDescription, sizeof(detail.strDescription) ) )
|
||||
ret = 3;
|
||||
|
||||
len = strlen( detail.strDescription );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], detail.strDescription, len );
|
||||
size += len;
|
||||
|
||||
char *pLen = &pData[size++];
|
||||
for( len=0; len<8; len++ ){
|
||||
pData[size++] = detail.aIntroBars[len];
|
||||
}
|
||||
*pLen = len;
|
||||
|
||||
pLen = &pData[size++];
|
||||
for( len=0; len<8; len++ ){
|
||||
pData[size++] = detail.aEndingBars[len];
|
||||
}
|
||||
*pLen = len;
|
||||
|
||||
pLen = &pData[size++];
|
||||
for( len=0; detail.chordRecom[len]>=0; len++ ){
|
||||
pData[size++] = detail.chordRecom[len];
|
||||
}
|
||||
*pLen = len;
|
||||
|
||||
int s, i, j;
|
||||
for( s=0; s<4; s++ ){
|
||||
int num = detail.nSegNum[s] & 0x0F;
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
pLen = &pData[size++];
|
||||
len = 0;
|
||||
|
||||
for( j=0; j<16 && detail.tracks[s][i][j].no>=0; j++ ){
|
||||
pData[size++] = detail.tracks[s][i][j].no;
|
||||
pData[size++] = detail.tracks[s][i][j].prog;
|
||||
pData[size++] = detail.tracks[s][i][j].vol;
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
}
|
||||
|
||||
if( s>=2 ){
|
||||
num = (detail.nSegNum[s] & 0xF0) >> 4;
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
pLen = &pData[size++];
|
||||
len = 0;
|
||||
|
||||
for( j=0; j<16 && detail.tracks[s][i+4][j].no>=0; j++ ){
|
||||
pData[size++] = detail.tracks[s][i+4][j].no;
|
||||
pData[size++] = detail.tracks[s][i+4][j].prog;
|
||||
pData[size++] = detail.tracks[s][i+4][j].vol;
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int StyleTrans2Detail( TSTYLEDETAIL &detail, int sizeData, char *pData )
|
||||
{
|
||||
int ret = 0,
|
||||
size = 0;
|
||||
|
||||
// fix part
|
||||
memcpy( &detail, pData, 20 );
|
||||
size += 20;
|
||||
|
||||
// var part
|
||||
int len;
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( detail.strAuthor, &pData[size], len );
|
||||
detail.strAuthor[len] = '\0';
|
||||
size += len;
|
||||
|
||||
if( TruncUTF8( detail.strAuthor, sizeof(detail.strAuthor) ) )
|
||||
ret = 1;
|
||||
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( detail.strStyleName, &pData[size], len );
|
||||
detail.strStyleName[len] = '\0';
|
||||
size += len;
|
||||
|
||||
if( TruncUTF8( detail.strStyleName, sizeof(detail.strStyleName) ) )
|
||||
ret = 2;
|
||||
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( detail.strDescription, &pData[size], len );
|
||||
detail.strDescription[len] = '\0';
|
||||
size += len;
|
||||
|
||||
if( TruncUTF8( detail.strDescription, sizeof(detail.strDescription) ) )
|
||||
ret = 3;
|
||||
|
||||
len = pData[size++];
|
||||
for( int i=0; i<len; i++ ){
|
||||
detail.aIntroBars[i] = pData[size++];
|
||||
}
|
||||
|
||||
len = pData[size++];
|
||||
for( int i=0; i<len; i++ ){
|
||||
detail.aEndingBars[i] = pData[size++];
|
||||
}
|
||||
|
||||
len = pData[size++];
|
||||
for( int i=0; i<len; i++ ){
|
||||
detail.chordRecom[i] = pData[size++];
|
||||
}
|
||||
|
||||
for( int s=0; s<4; s++ ){
|
||||
bool bSep = false;
|
||||
int num = detail.nSegNum[s];
|
||||
|
||||
if( num>0x1F ){
|
||||
num &= 0x0F;
|
||||
bSep = true;
|
||||
}
|
||||
else if( s>=2 ){
|
||||
num *= 2;
|
||||
}
|
||||
|
||||
for( int i=0; i<num; i++ ){
|
||||
len = pData[size++];
|
||||
|
||||
for( int j=0; j<len; j++ ){
|
||||
detail.tracks[s][i][j].no = pData[size++];
|
||||
detail.tracks[s][i][j].prog = pData[size++];
|
||||
detail.tracks[s][i][j].vol = pData[size++];
|
||||
}
|
||||
}
|
||||
|
||||
if( bSep ){
|
||||
num = (detail.nSegNum[s] & 0xF0) >> 4;
|
||||
|
||||
for( int i=0; i<num; i++ ){
|
||||
len = pData[size++];
|
||||
|
||||
for( int j=0; j<len; j++ ){
|
||||
detail.tracks[s][i+4][j].no = pData[size++];
|
||||
detail.tracks[s][i+4][j].prog = pData[size++];
|
||||
detail.tracks[s][i+4][j].vol = pData[size++];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( size!=sizeData ){
|
||||
DebugPrint("size: %d, sizeData: %d\n", size, sizeData);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ShareInfo2Trans( TSTYLESHARE& info, int &size, char *pData )
|
||||
{
|
||||
size = 0;
|
||||
// fix part
|
||||
memcpy( pData, &info, 64 );
|
||||
size += 64;
|
||||
|
||||
// var part
|
||||
int len;
|
||||
len = strlen( info.strAuthor );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], info.strAuthor, len );
|
||||
size += len;
|
||||
|
||||
len = strlen( info.strStyleName );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], info.strStyleName, len );
|
||||
size += len;
|
||||
|
||||
len = strlen( info.strDescription );
|
||||
pData[size++] = (BYTE)len;
|
||||
memcpy( &pData[size], info.strDescription, len );
|
||||
size += len;
|
||||
|
||||
int s, i, j;
|
||||
for( s=0; s<4; s++ ){
|
||||
int num = info.nSegNum[s] & 0x0F;
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
char* pLen = &pData[size++];
|
||||
|
||||
len = 0;
|
||||
for( j=0; j<16 && info.trkRef[s][i][j].idStyle>0; j++ ){
|
||||
*(UINT*)(&pData[size]) = info.trkRef[s][i][j].idStyle;
|
||||
size += 4;
|
||||
pData[size++] = info.trkRef[s][i][j].segNo;
|
||||
pData[size++] = info.trkRef[s][i][j].chan;
|
||||
pData[size++] = info.trkRef[s][i][j].prog;
|
||||
pData[size++] = info.trkRef[s][i][j].vol;
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
}
|
||||
|
||||
if( s>=2 ){
|
||||
num = (info.nSegNum[s] & 0xF0) >> 4;
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
char* pLen = &pData[size++];
|
||||
len = 0;
|
||||
|
||||
for( j=0; j<16 && info.trkRef[s][i+4][j].idStyle>0; j++ ){
|
||||
*(UINT*)(&pData[size]) = info.trkRef[s][i+4][j].idStyle;
|
||||
size += 4;
|
||||
|
||||
pData[size++] = info.trkRef[s][i+4][j].segNo;
|
||||
pData[size++] = info.trkRef[s][i+4][j].chan;
|
||||
pData[size++] = info.trkRef[s][i+4][j].prog;
|
||||
pData[size++] = info.trkRef[s][i+4][j].vol;
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
*pLen = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ShareTrans2Info( TSTYLESHARE& info, int sizeData, char *pData )
|
||||
{
|
||||
int s, i, j, size = 0;
|
||||
|
||||
// fix part
|
||||
memcpy( &info, pData, 64 );
|
||||
size += 64;
|
||||
|
||||
// var part
|
||||
int len;
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( info.strAuthor, &pData[size], len );
|
||||
info.strAuthor[len] = '\0';
|
||||
size += len;
|
||||
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( info.strStyleName, &pData[size], len );
|
||||
info.strStyleName[len] = '\0';
|
||||
size += len;
|
||||
|
||||
len = (BYTE)pData[size++];
|
||||
memcpy( info.strDescription, &pData[size], len );
|
||||
info.strDescription[len] = '\0';
|
||||
size += len;
|
||||
|
||||
for( s=0; s<4; s++ ){
|
||||
bool bSep = false;
|
||||
int num = info.nSegNum[s];
|
||||
|
||||
if( num>0x1F ){
|
||||
num &= 0x0F;
|
||||
bSep = true;
|
||||
}
|
||||
else if( s>=2 ){
|
||||
num *= 2;
|
||||
}
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
len = pData[size++];
|
||||
|
||||
for( j=0; j<len; j++ ){
|
||||
info.trkRef[s][i][j].idStyle = *(UINT*)(&pData[size]);
|
||||
size += 4;
|
||||
|
||||
info.trkRef[s][i][j].segNo = pData[size++];
|
||||
info.trkRef[s][i][j].chan = pData[size++];
|
||||
info.trkRef[s][i][j].prog = pData[size++];
|
||||
info.trkRef[s][i][j].vol = pData[size++];
|
||||
}
|
||||
}
|
||||
|
||||
if( bSep ){
|
||||
num = (info.nSegNum[s] & 0xF0) >> 4;
|
||||
|
||||
for( i=0; i<num; i++ ){
|
||||
len = pData[size++];
|
||||
|
||||
for( j=0; j<len; j++ ){
|
||||
info.trkRef[s][i+4][j].idStyle = *(UINT*)(&pData[size]);
|
||||
size += 4;
|
||||
|
||||
info.trkRef[s][i+4][j].segNo = pData[size++];
|
||||
info.trkRef[s][i+4][j].chan = pData[size++];
|
||||
info.trkRef[s][i+4][j].prog = pData[size++];
|
||||
info.trkRef[s][i+4][j].vol = pData[size++];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size==sizeData;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
string UTF8ToGBK(const string& strUTF8)
|
||||
{
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, NULL, 0);
|
||||
// unsigned short * wszGBK = new unsigned short[len + 1];
|
||||
wchar_t* wszGBK = new wchar_t[len + 1];
|
||||
memset(wszGBK, 0, len * 2 + 2);
|
||||
MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8.c_str(), -1, wszGBK, len);
|
||||
|
||||
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
||||
char *szGBK = new char[len + 1];
|
||||
memset(szGBK, 0, len + 1);
|
||||
WideCharToMultiByte(CP_ACP,0, wszGBK, -1, szGBK, len, NULL, NULL);
|
||||
//strUTF8 = szGBK;
|
||||
string strTemp(szGBK);
|
||||
delete[]szGBK;
|
||||
delete[]wszGBK;
|
||||
return strTemp;
|
||||
}
|
||||
|
||||
int UTF8ToGBK(const char *pcUtf8, string & strGBK)
|
||||
{
|
||||
|
||||
//wchar_t pcUnicode[CHAR_BUFSIZE];
|
||||
|
||||
int nUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, NULL, 0);
|
||||
|
||||
wchar_t * pcUnicode = new wchar_t[nUnicodeLen+1];
|
||||
memset(pcUnicode, 0, nUnicodeLen * 2 + 2);
|
||||
|
||||
//utf8 to unicode
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, pcUnicode, nUnicodeLen);
|
||||
|
||||
//unicode to GBK
|
||||
|
||||
int nGBKLen = WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, NULL, 0, NULL, NULL);
|
||||
|
||||
char *pcGBK=new char[nGBKLen + 1];
|
||||
memset(pcGBK, 0, nGBKLen + 1);
|
||||
|
||||
WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, pcGBK, nGBKLen, NULL, NULL);
|
||||
|
||||
strGBK=pcGBK;
|
||||
delete[] pcGBK;
|
||||
delete[] pcUnicode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GBKToUTF8(const char *pcGBK, string & strUtf8)
|
||||
{
|
||||
//GBK to unicode
|
||||
int nUnicodeLen = MultiByteToWideChar(CP_ACP, 0, pcGBK, -1, NULL, 0);
|
||||
|
||||
wchar_t * pcUnicode = new wchar_t[nUnicodeLen+1];
|
||||
memset(pcUnicode, 0, nUnicodeLen * 2 + 2);
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, pcGBK, -1, pcUnicode, nUnicodeLen);
|
||||
|
||||
|
||||
//unicode to utf8
|
||||
int nUtf8Len = WideCharToMultiByte(CP_UTF8, 0, pcUnicode, -1, NULL, 0, NULL, NULL);
|
||||
|
||||
char *pcUtf8=new char[nUtf8Len + 1];
|
||||
memset(pcUtf8, 0, nUtf8Len + 1);
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, pcUnicode, -1, pcUtf8, nUtf8Len, NULL, NULL);
|
||||
|
||||
strUtf8=pcUtf8;
|
||||
delete[] pcUtf8;
|
||||
delete[] pcUnicode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,444 @@
|
||||
#ifndef MessageDefH
|
||||
#define MessageDefH
|
||||
|
||||
#include "ProCommon.h"
|
||||
|
||||
//////////////////////////////////////////////
|
||||
#define PROTOCOL_VERSION 0x0D00
|
||||
// 0x0100 Request的iExtra包含ClientType和MsgVer
|
||||
// 0x0200 (2013.10.30) Verify MMParam2算法
|
||||
// 0x0300 (2013.11.13) 启用新TSTYLEUPDATE/TSTYLEDETAIL结构(传输优化)
|
||||
// 0x0400 (2014.02.19) QnACommit 增加版本号 dataSend返回e_ReceiveComplete
|
||||
// 0x0500 (2014.03.25) Payment MMParam2算法 修改版本号规则
|
||||
// 0x0600 (2014.06.23) 启用新TSTYLEUPDATE/TACCOUNTINFO/TPayRequest/TLogReq(Rsp)/TRegisterReq(Rsp)结构
|
||||
// 0x0700 (2014.07.18) 启用新TStyleUpdateReq/TStyleInfoResp/TLoginResp结构
|
||||
// 0x0800 (2015.01.26) 新TACCOUNTINFO/TLoginRequest/TLogoffRequest结构
|
||||
// 0x0900 (2015.05.28) VersionReq增加设备号
|
||||
// 0x0A00 (2015.12.17) 更新RegisterReq/LoginRes/CheckReq/Res/PayReq/Res结构及算法
|
||||
// 0x0B00 (2025.01.20) 更新RegisterReq结构,connectReq带版本号
|
||||
// 0x0C00 (2025.02.18) 增加 e_UserLocked/e_UserDeleted错误返回
|
||||
// ox0D00 (2025.11.30) NetMessage增加idDevice
|
||||
|
||||
#define LISTEN_PORT 12071
|
||||
|
||||
#define MAX_MSG_LENGTH 8192
|
||||
#define MAX_PACK_SIZE 1400
|
||||
#define MAX_STYLE_NUM 80
|
||||
#define MAX_QNA_NUM 80
|
||||
#define MAX_NOTICE_NUM 80
|
||||
|
||||
#define MSG_OPERATE_FAILED WM_USER + 0x105
|
||||
#define MSG_OPERATE_PERCENT WM_USER + 0x106
|
||||
#define MSG_OPERATE_COMPLETE WM_USER + 0x107
|
||||
#define MSG_NETWORKMESSAGE WM_USER + 0x130
|
||||
#define MSG_NETWORKERROR WM_USER + 0x131
|
||||
|
||||
#define URL_HOMEPAGE 0 //网站主页
|
||||
#define URL_USERCENTER 1 //用户中心页
|
||||
#define URL_SONGMANAGE 2 //歌曲管理页
|
||||
#define URL_SOFTWARE 3 //软件下载页
|
||||
#define URL_USERNOTICE 4 //用户消息页
|
||||
#define URL_TECHFORUM 5 //技术论坛
|
||||
#define URL_SHAREPLAY 6 //分享播放页
|
||||
#define URL_JASONQUERY 7 //JASON
|
||||
#define URL_RECHARGE 8 //充值页
|
||||
#define URL_VIPMEMBER 9 //VIP会员页
|
||||
#define URL_SONGPLAY 10 //歌曲播放页
|
||||
#define URL_COINSPEC 11 //唱作音符说明页
|
||||
#define URL_EXTFONT 12 //扩展音色库下载页
|
||||
#define URL_USERAGREEMENT 13 //用户协议页
|
||||
#define URL_REGCODE 14 //注册验证码接口
|
||||
#define URL_RESETPASS 15 //重置密码页
|
||||
|
||||
#pragma once
|
||||
|
||||
enum EMessageType{
|
||||
e_InvalidMessage,
|
||||
|
||||
e_versionRequest = 0x01,
|
||||
e_versionResponse,
|
||||
|
||||
e_connectRequest = 0x11,
|
||||
e_connectResponse,
|
||||
|
||||
e_loginRequest = 0x21,
|
||||
e_loginResponse,
|
||||
e_verifyRequest,
|
||||
e_verifyResponse,
|
||||
e_purchaseRequest,
|
||||
e_purchaseResponse,
|
||||
e_registerRequest,
|
||||
e_registerResponse,
|
||||
e_checkPaymentRequest,
|
||||
e_checkPaymentResponse,
|
||||
e_payRequest,
|
||||
e_payResponse,
|
||||
e_iconRequest,
|
||||
e_iconResponse,
|
||||
e_logoffRequest,
|
||||
e_logoffResponse,
|
||||
e_webURLRequest = 0x31,
|
||||
e_webURLResponse,
|
||||
|
||||
e_dataSendRequest = 0x41,
|
||||
e_dataSendResponse,
|
||||
e_dataReceiveRequest,
|
||||
e_dataReceiveResponse,
|
||||
|
||||
e_styleUpdateRequest = 0x61,
|
||||
e_styleUpdateResponse,
|
||||
e_styleInfoRequest,
|
||||
e_styleInfoResponse,
|
||||
e_styleDataRequest,
|
||||
e_styleDataResponse,
|
||||
e_styleCheckRequest,
|
||||
e_styleCheckResponse,
|
||||
e_styleRecomRequest,
|
||||
e_styleRecomResponse,
|
||||
e_styleScoreRequest,
|
||||
e_styleScoreResponse,
|
||||
|
||||
e_uploadStyleRequest = 0x81,
|
||||
e_uploadStyleResponse,
|
||||
e_uploadSongRequest,
|
||||
e_uploadSongResponse,
|
||||
|
||||
e_qnaUpdateRequest = 0x91,
|
||||
e_qnaUpdateResponse,
|
||||
e_qnaSubmitRequest,
|
||||
e_qnaSubmitResponse,
|
||||
e_noticeUpdateRequest,
|
||||
e_noticeUpdateResponse,
|
||||
|
||||
e_MessgeTypeEnd
|
||||
};
|
||||
|
||||
enum EExtraInfo{
|
||||
e_RequestSuccess,
|
||||
|
||||
e_UpdateNoNeed, //已是最新版本
|
||||
e_UpdateOptional, //版本可选更新
|
||||
e_UpdateMandatory, //版本强制更新
|
||||
|
||||
e_VerifyInsufficient, //账户余额不足
|
||||
e_ReceiveComplete, //数据接收完成
|
||||
|
||||
e_ShareStyle = 0x100, //分享风格信息
|
||||
e_CheckStyle = 0x101, //审核风格信息
|
||||
|
||||
e_RequestFailed = 0x8000,
|
||||
e_SocketError,
|
||||
e_WaitTimeout,
|
||||
e_DatabaseError,
|
||||
e_ParamError,
|
||||
e_LoginPasswordError,
|
||||
e_LoginUserNotExist,
|
||||
e_InvalidUserID,
|
||||
e_InvalidStyleID,
|
||||
|
||||
e_UserCanceled,
|
||||
e_NoService,
|
||||
e_ServiceBusy,
|
||||
|
||||
e_InvalidDataID,
|
||||
e_InvalidPackID,
|
||||
e_OutOfBound,
|
||||
e_InvalidData,
|
||||
e_InvalidAuthority, //无操作权限
|
||||
e_CheckedAlready, //风格已被审核
|
||||
|
||||
e_UsernameExist,
|
||||
e_OpenFileFailed,
|
||||
|
||||
e_NeedRepeat, //需重发消息
|
||||
|
||||
e_VipExceeded, //VIP用户设备数超限
|
||||
e_UserLocked, //账户被冻结
|
||||
e_UserDeleted, //账户已删除
|
||||
|
||||
e_ExtraEnd
|
||||
};
|
||||
|
||||
enum EUploadOperation{
|
||||
e_UO_Create,
|
||||
e_UO_Distribute,
|
||||
e_UO_Share,
|
||||
e_UO_END
|
||||
};
|
||||
|
||||
#pragma pack (2)
|
||||
|
||||
typedef struct tNetMessage{
|
||||
unsigned char idDevice[6]; //设备号,一般为mac地址
|
||||
unsigned short nSequenceNum; // 消息序列号,Request/Response匹配
|
||||
unsigned short eMessageType; // 消息类型
|
||||
unsigned short iExtra; // 额外信息
|
||||
unsigned short nLength; // 消息体的有效长度
|
||||
unsigned char byMessageBody[MAX_MSG_LENGTH]; // 消息体:消息参数部分
|
||||
|
||||
tNetMessage(){ memset( this, 0, sizeof(tNetMessage) ); };
|
||||
} TNETMESSAGE;
|
||||
|
||||
typedef struct {
|
||||
int iReq;
|
||||
} TIntRequest;
|
||||
|
||||
typedef struct {
|
||||
int iResp;
|
||||
} TIntResponse;
|
||||
|
||||
typedef struct {
|
||||
char sReq[256];
|
||||
} TStringRequest;
|
||||
|
||||
typedef struct {
|
||||
char sResp[256];
|
||||
} TStringResponse;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwVersionMS;
|
||||
DWORD dwVersionLS;
|
||||
} TVersionRequest;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwVersionMS; //最新版本号
|
||||
DWORD dwVersionLS;
|
||||
UINT tIssueDate;
|
||||
UINT nFileSize;
|
||||
UINT nDescribLen;
|
||||
char strDescrib[MAX_DESCRIB_LENGTH];
|
||||
} TVersionResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iClientType;
|
||||
UINT idUser;
|
||||
UINT tUpdateDateOrigin;
|
||||
UINT tUpdateDateShare;
|
||||
} TStyleUpdateRequest;
|
||||
|
||||
typedef struct {
|
||||
WORD nOriginNum;
|
||||
WORD nShareNum;
|
||||
UINT tUpdateDateOrigin;
|
||||
UINT tUpdateDateShare;
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TStyleUpdateResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT nRecomNum;
|
||||
UINT aStyleIDs[MAX_STYLE_NUM];
|
||||
} TStyleRecomResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iType;
|
||||
UINT idStyle;
|
||||
} TStyleInfoRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TStyleInfoResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iType;
|
||||
UINT idStyle;
|
||||
} TStyleDataRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TStyleDataResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
UINT idStyle;
|
||||
short iType;
|
||||
short scrUser;
|
||||
} TStyleScoreRequest;
|
||||
|
||||
typedef struct {
|
||||
short scrUser;
|
||||
short scrAverage;
|
||||
} TStyleScoreResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idChecker; //审核者ID
|
||||
UINT idStyle;
|
||||
WORD score; //0=未通过
|
||||
WORD lenMsg; //问题描述信息长度
|
||||
char strDescrib[MAX_DESCRIB_LENGTH];
|
||||
} TStyleCheckRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idStyle;
|
||||
} TStyleCheckResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
short isEmailOrMobile;
|
||||
} TRegisterRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
UINT idUser;
|
||||
char strNickname[32];
|
||||
} TRegisterResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
// char idDevice[6];
|
||||
} TLoginRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strNickname[32];
|
||||
char strIconFile[32];
|
||||
TACCOUNTINFO accountInfo;
|
||||
} TLoginResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
// char idDevice[6];
|
||||
} TLogoffRequest;
|
||||
|
||||
typedef struct {
|
||||
char strIconFile[32];
|
||||
} TIconRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TIconResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
UINT dwMMParam;
|
||||
WORD wOperation;
|
||||
WORD wStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TCheckPaymentRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT dwMMParam;
|
||||
int nUserBalance;
|
||||
int nPayment;
|
||||
int aStyleCost[MAX_STYLE_NUM];
|
||||
} TCheckPaymentResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
// UINT dwMMParam;
|
||||
WORD wOperation;
|
||||
WORD wStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TPayRequest;
|
||||
|
||||
typedef struct {
|
||||
// UINT dwMMParam;
|
||||
int nUserBalance;
|
||||
} TPayResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iType; //风格类型 1=批量上传 2=制作上传 3=分享上传
|
||||
UINT idUser;
|
||||
UINT nDataSize;
|
||||
} TUploadStyleRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idFile;
|
||||
} TUploadStyleResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iClientType;
|
||||
UINT idUser;
|
||||
UINT nDataSize;
|
||||
} TUploadSongRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idFile;
|
||||
} TUploadSongResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT idPacket;
|
||||
UINT nPackSize;
|
||||
char arrPacket[MAX_PACK_SIZE];
|
||||
} TDataSendRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT idPacket;
|
||||
} TDataSendResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT idPacket;
|
||||
} TDataReceiveRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT idPacket;
|
||||
UINT nPackSize;
|
||||
char arrPacket[MAX_PACK_SIZE];
|
||||
} TDataReceiveResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iClientType;
|
||||
UINT tLastUpdateDate;
|
||||
UINT idUser;
|
||||
UINT nQnANum;
|
||||
UINT aIdQnAs[MAX_QNA_NUM];
|
||||
} TQnAUpdateRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT tUpdateDate;
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TQnAUpdateResponse;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwVersionMS;
|
||||
DWORD dwVersionLS;
|
||||
UINT idUser;
|
||||
char strQuestion[320];
|
||||
} TQnASubmitRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idQnA;
|
||||
} TQnASubmitResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
UINT nNoticeNum;
|
||||
UINT aIdNotices[MAX_NOTICE_NUM];
|
||||
} TNoticeUpdateRequest;
|
||||
|
||||
typedef struct {
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TNoticeUpdateResponse;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
bool ValidNetMessage(unsigned char* buf, int len);
|
||||
bool ReadNetMessage( unsigned char* buf, short len, TNETMESSAGE* pMsg );
|
||||
bool WriteNetMessage( unsigned char* buf, short& len, TNETMESSAGE* pMsg );
|
||||
|
||||
int StyleDetail2Trans( TSTYLEDETAIL& detail, int &size, char *pData );
|
||||
int StyleTrans2Detail( TSTYLEDETAIL& detail, int sizeData, char *pData );
|
||||
int ShareInfo2Trans( TSTYLESHARE& detail, int &size, char *pData );
|
||||
bool ShareTrans2Info( TSTYLESHARE& info, int sizeData, char *pData );
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <string>
|
||||
using namespace std;
|
||||
int GBKToUTF8(const char *pcGBK, string & strUTF8);
|
||||
int UTF8ToGBK(const char *pcUTF8, string & strGBK);
|
||||
#endif
|
||||
|
||||
#endif //_MESSAGEDEF_H_
|
||||
@@ -0,0 +1,136 @@
|
||||
#ifndef ProCommonH
|
||||
#define ProCommonH
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "commonstruct.h"
|
||||
|
||||
#pragma pack (2)
|
||||
|
||||
//Track引用信息
|
||||
typedef struct tagTrackRef{
|
||||
UINT idLoc; //位置id
|
||||
UINT idStyle; //风格ID
|
||||
char segNo; //原片段号
|
||||
char chan; //原通道号
|
||||
char prog; //乐器号
|
||||
char vol; //音量
|
||||
}TTRACKREF, *PTTRACKREF;
|
||||
|
||||
//原创风格信息
|
||||
typedef struct tagStyleOrigin{
|
||||
WORD cost; //使用消费
|
||||
WORD score; //评分 (score/100)10分制
|
||||
int paid; //支付次数
|
||||
int state; //状态
|
||||
|
||||
TSTYLEDETAIL detail;
|
||||
|
||||
tagStyleOrigin(){
|
||||
cost = 0;
|
||||
score = 0;
|
||||
paid = 0;
|
||||
state = 0;
|
||||
}
|
||||
}TSTYLEORIGIN, *PTSTYLEORIGIN;
|
||||
|
||||
//本地风格信息
|
||||
typedef struct tagStyleLocal{
|
||||
short iTempo; //原速
|
||||
short iTimesignature; //节拍 ( 0=4/4, 1=3/4, 2=2/4, 3=6/8 )
|
||||
|
||||
char strStyleName[40]; //风格名称 UTF8
|
||||
char nSegNum[4]; //伴奏/加花/前奏/尾奏个数
|
||||
char aIEBars[2][8]; //前/尾奏小节数 (0-3大调 4-7小调)
|
||||
char nSegVol[4][8]; //片段音量
|
||||
|
||||
TTRACKREF trkRef[4][8][16]; //轨道引用信息
|
||||
|
||||
tagStyleLocal(){
|
||||
memset( this, 0, sizeof(tagStyleLocal) );
|
||||
}
|
||||
}TSTYLELOCAL, *PTSTYLELOCAL;
|
||||
|
||||
//分享Track引用信息
|
||||
typedef struct tagShareTrackRef{
|
||||
UINT idStyle; //原创风格ID
|
||||
char segNo; //原片段号
|
||||
char chan; //原通道号
|
||||
char prog; //乐器号
|
||||
char vol; //音量
|
||||
}TSHARETRACKREF, *PTSHARETRACKREF;
|
||||
|
||||
//分享的重组风格信息
|
||||
typedef struct tagStyleShare{
|
||||
int idAuthor; //作者ID
|
||||
WORD score; //评分 (score/100)10分制
|
||||
|
||||
short iTempo; //原速
|
||||
short iTimesignature; //节拍 ( 0=4/4, 1=3/4, 2=2/4, 3=6/8 )
|
||||
char type[2]; //风格分类
|
||||
char nSegNum[4]; //伴奏/加花/前奏/尾奏个数
|
||||
char aIEBars[2][8]; //前/尾奏小节数 (0-3大调 4-7小调)
|
||||
char nSegVol[4][8]; //片段音量
|
||||
|
||||
//以下部分可变长度传输和存储
|
||||
char strAuthor[40]; //作者名称 UTF8
|
||||
char strStyleName[40]; //风格名称 UTF8
|
||||
char strDescription[120]; //风格描述 UTF8
|
||||
|
||||
TSHARETRACKREF trkRef[4][8][16]; //轨道引用信息
|
||||
|
||||
tagStyleShare(){
|
||||
memset( this, 0, sizeof(tagStyleShare) );
|
||||
}
|
||||
}TSTYLESHARE, *PTSTYLESHARE;
|
||||
|
||||
//专业版风格结构体
|
||||
typedef struct tagProStyle{
|
||||
UINT idLoc; //位置id
|
||||
UINT idStyle; //风格ID
|
||||
|
||||
union{
|
||||
PTSTYLEORIGIN pOrigin;
|
||||
PTSTYLELOCAL pLocal;
|
||||
PTSTYLESHARE pShare;
|
||||
};
|
||||
|
||||
tagProStyle(){
|
||||
memset( this, 0, sizeof(tagProStyle) );
|
||||
}
|
||||
|
||||
~tagProStyle(){
|
||||
if( idLoc==0 ){
|
||||
if( pOrigin )
|
||||
delete pOrigin;
|
||||
}
|
||||
else if( idLoc==1 ){
|
||||
if( pShare )
|
||||
delete pShare;
|
||||
}
|
||||
else{
|
||||
if( pLocal )
|
||||
delete pLocal;
|
||||
}
|
||||
}
|
||||
}TPROSTYLE, *PTPROSTYLE;
|
||||
|
||||
//分享风格更新结构体
|
||||
typedef struct tShareUpdate{
|
||||
UINT idStyle; //风格ID
|
||||
WORD score; //评分 (score/100)10分制
|
||||
WORD reserved; //保留,对齐字节
|
||||
} TSHAREUPDATE, *PTSHAREUPDATE;
|
||||
|
||||
//待审核风格更新结构体
|
||||
typedef struct tCheckUpdate{
|
||||
UINT idStyle; //风格ID
|
||||
short cost; //定价
|
||||
WORD reserved; //保留,对齐字节
|
||||
} TCHECKUPDATE, *PTCHECKUPDATE;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif //_COMMONSTRUCT_H_
|
||||
@@ -0,0 +1,325 @@
|
||||
#ifndef ServerInnerH
|
||||
#define ServerInnerH
|
||||
|
||||
#pragma once
|
||||
|
||||
//功能费定义(单位:音符)
|
||||
#define PAY_BASIC 1 // 基本费
|
||||
#define PAY_MIDICOMPOSE 20 // 伴奏MIDI
|
||||
#define PAY_MIDITRANS 50 // 音频转MIDI
|
||||
#define PAY_MULTIAUDIO 30 // 多音轨
|
||||
#define PAY_MULTIFONT 80 // 多音色库
|
||||
|
||||
#define MAX_STYLE_NUM 80
|
||||
|
||||
#pragma pack (2)
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//风格详细信息结构体 (兼容早期版本)
|
||||
typedef struct tagStyleDetail0{
|
||||
int size;
|
||||
int idAuthor; //作者ID
|
||||
|
||||
int iTempo; //原速
|
||||
short iTimesignature; //节拍 ( 0=4/4, 1=3/4, 2=2/4, 3=6/8 )
|
||||
char nSegNum[4]; //伴奏/加花/前奏/尾奏个数
|
||||
char aIntroBars[8]; //前奏小节数
|
||||
char aEndingBars[8]; //尾奏小节数
|
||||
|
||||
char strStyleName[40]; //风格名称 UTF8
|
||||
char strDescription[120];//风格描述 UTF8
|
||||
char strAuthor[40]; //作者名称 UTF8
|
||||
char type[6]; //风格分类
|
||||
char progVar[4][3]; //伴奏主要乐器
|
||||
char progIntro[4][3]; //前奏主要乐器
|
||||
char progEnding[4][3]; //尾奏主要乐器
|
||||
char chordRecom[8]; //推荐和声进行
|
||||
|
||||
tagStyleDetail0(){
|
||||
size = sizeof(tagStyleDetail0);
|
||||
idAuthor = iTempo = iTimesignature = 0;
|
||||
memset( nSegNum, 0, sizeof(nSegNum) );
|
||||
memset( aIntroBars, 0, sizeof(aIntroBars) );
|
||||
memset( aEndingBars, 0, sizeof(aEndingBars) );
|
||||
memset( strStyleName, 0, sizeof(strStyleName) );
|
||||
memset( strDescription, 0, sizeof(strDescription) );
|
||||
memset( strAuthor, 0, sizeof(strAuthor) );
|
||||
memset( type, -1, sizeof(type) );
|
||||
memset( progVar, -1, sizeof(progVar) );
|
||||
memset( progIntro, -1, sizeof(progIntro) );
|
||||
memset( progEnding, -1, sizeof(progEnding) );
|
||||
memset( chordRecom, -1, sizeof(chordRecom) );
|
||||
}
|
||||
}TSTYLEDETAIL0, *PTSTYLEDETAIL0;
|
||||
|
||||
//风格信息结构体
|
||||
typedef struct tagStyleInfo0{
|
||||
UINT idStyle; //风格ID
|
||||
int cost; //价格
|
||||
int state; //状态
|
||||
TSTYLEDETAIL0 detail; //详细信息
|
||||
|
||||
tagStyleInfo0(){
|
||||
idStyle = 0;
|
||||
cost = 0;
|
||||
state = 0;
|
||||
}
|
||||
}TSTYLEINFO0, *PTSTYLEINFO0;
|
||||
|
||||
//账户信息结构体
|
||||
typedef struct tAccountInfo1{
|
||||
int size; //数据长度
|
||||
UINT ID; //用户ID
|
||||
UINT authority; //用户权限
|
||||
int balance; //帐户余额(唱作音符)
|
||||
int pops; //魅力值
|
||||
int fans; //粉丝数
|
||||
int songs; //歌曲数
|
||||
int ownStyleNum; //已购买风格数
|
||||
int arrStyleId[16]; //已购买风格ID数组
|
||||
|
||||
tAccountInfo1(){
|
||||
memset( this, 0, sizeof(tAccountInfo1) );
|
||||
size = 32;
|
||||
};
|
||||
}TACCOUNTINFO1, *PTACCOUNTINFO1;
|
||||
//
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//前向兼容网络消息
|
||||
typedef struct {
|
||||
UINT tLastUpdateDate;
|
||||
DWORD dwVersionMS;
|
||||
DWORD dwVersionLS;
|
||||
} TVersionRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT nAvailibleNum;
|
||||
DWORD dwVersionMS; //最新版本号
|
||||
DWORD dwVersionLS;
|
||||
UINT tIssueDate;
|
||||
UINT nFileSize;
|
||||
UINT nDescribLen;
|
||||
char strDescrib[MAX_DESCRIB_LENGTH];
|
||||
} TVersionResponse0;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwVersionMS;
|
||||
DWORD dwVersionLS;
|
||||
} TVersionRequest1;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwVersionMS;
|
||||
DWORD dwVersionLS;
|
||||
char idDevice[6];
|
||||
} TVersionRequest2;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
DWORD dwMMParam;
|
||||
UINT nStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TVerifyRequest;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwMMParam;
|
||||
UINT nStyleNum;
|
||||
float fUserBalance;
|
||||
float aStylePrices[MAX_STYLE_NUM*2];
|
||||
} TVerifyResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
WORD iapType; //应用内付费类型:0=个人账户,1=移动IAP
|
||||
WORD nStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TPurchaseRequest;
|
||||
|
||||
typedef struct {
|
||||
float fUserBalance;
|
||||
} TPurchaseResponse;
|
||||
|
||||
typedef struct {
|
||||
UINT iClientType;
|
||||
UINT idUser;
|
||||
char strQuestion[320];
|
||||
} TQnASubmitRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
WORD wOperation;
|
||||
WORD wStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TCheckPaymentRequest0;
|
||||
|
||||
typedef struct {
|
||||
int nUserBalance;
|
||||
int nPayment;
|
||||
} TCheckPaymentResponse0;
|
||||
|
||||
typedef struct {
|
||||
int nUserBalance;
|
||||
int nPayment;
|
||||
int aStyleCost[MAX_STYLE_NUM];
|
||||
} TCheckPaymentResponse1;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
UINT dwMMParam;
|
||||
WORD wOperation;
|
||||
WORD wStyleNum;
|
||||
UINT aIdStyles[MAX_STYLE_NUM];
|
||||
} TPayRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT dwMMParam;
|
||||
int nUserBalance;
|
||||
} TPayResponse0;
|
||||
|
||||
typedef struct {
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
} TLoginRequest0;
|
||||
|
||||
typedef struct {
|
||||
TACCOUNTINFO1 accountInfo;
|
||||
} TLoginResponse0;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
char idDevice[6];
|
||||
} TLogoffRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
} TLoginRequest1;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
char idDevice[6];
|
||||
} TLoginRequest2;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strNickname[32];
|
||||
TACCOUNTINFO1 accountInfo;
|
||||
} TLoginResponse1;
|
||||
|
||||
typedef struct {
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
} TRegisterRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
} TRegisterRequest1;
|
||||
|
||||
typedef struct {
|
||||
UINT param;
|
||||
char strName[32];
|
||||
char strPassword[80];
|
||||
char strNickname[32]; //昵称
|
||||
char idDevice[6]; //设备号
|
||||
char strCode[80]; //验证码
|
||||
} TRegisterRequest2;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
char strNickname[32];
|
||||
} TRegisterResponse0;
|
||||
|
||||
typedef struct {
|
||||
UINT idStyle;
|
||||
int verDetail; //信息版本
|
||||
int size;
|
||||
char detail[1400];
|
||||
} TStyleInfoResponse0;
|
||||
|
||||
typedef struct {
|
||||
UINT idUser;
|
||||
UINT idStyle;
|
||||
short scrUser;
|
||||
} TStyleScoreRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT iClientType;
|
||||
UINT idUser;
|
||||
UINT tLastUpdateDate;
|
||||
} TStyleUpdateRequest0;
|
||||
|
||||
typedef struct {
|
||||
UINT nAvailibleNum;
|
||||
UINT tUpdateDate;
|
||||
UINT idData;
|
||||
UINT nDataSize;
|
||||
} TStyleUpdateResponse0;
|
||||
|
||||
#pragma pack (4)
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//兼容早期版本
|
||||
typedef struct tStylePrice{
|
||||
UINT idStyle; //风格ID
|
||||
float fPrice; //价格
|
||||
} TSTYLEPRICE, *PTSTYLEPRICE;
|
||||
|
||||
typedef struct tStyleUpdate0{
|
||||
UINT idStyle; //风格ID
|
||||
int price; //购买消费
|
||||
int cost; //使用消费
|
||||
int score; //评分 (score/100)10分制
|
||||
} TSTYLEUPDATE0, *PTSTYLEUPDATE0;
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
//账户信息结构体
|
||||
typedef struct tAccountInfo0{
|
||||
int size; //数据长度
|
||||
UINT ID; //用户ID
|
||||
int balance; //帐户余额(唱作音符)
|
||||
int pops; //魅力值
|
||||
int fans; //粉丝数
|
||||
int songs; //歌曲数
|
||||
int ownStyleNum; //已购买风格数
|
||||
|
||||
tAccountInfo0(){
|
||||
memset( this, 0, sizeof(tAccountInfo0) );
|
||||
size = 28;
|
||||
};
|
||||
}TACCOUNTINFO0, *PTACCOUNTINFO0;
|
||||
|
||||
//上传歌曲信息结构体
|
||||
typedef struct tSongInfo0{
|
||||
int size; //结构大小
|
||||
char strSongName[64]; //歌曲名
|
||||
int iTempo; //速度
|
||||
char iTS; //节拍
|
||||
char iCreation; //创作类型 (1:原创 3:改编)
|
||||
char iSubmit; //提交审核状态(0:不提交,1:自动提交)
|
||||
char iSingerType; //演唱人类别 (1:男;2:女;3:组合;4:其他;0:未知)
|
||||
char strSinger[32]; //演唱
|
||||
char strOriginal[32]; //原唱
|
||||
char strLyricist[32]; //作词
|
||||
char strComposer[32]; //作曲
|
||||
char strArranger[32]; //编曲
|
||||
char iMusicStyle[4]; //曲风
|
||||
UINT aStyleIDs[32]; //使用的风格ID
|
||||
char strDescription[640];//歌曲描述
|
||||
|
||||
tSongInfo0(){
|
||||
memset( this, 0, sizeof(tSongInfo0) );
|
||||
memset( iMusicStyle, -1, 4 );
|
||||
size = sizeof(tSongInfo0);
|
||||
};
|
||||
|
||||
} TSONGINFO0, *PTSONGINFO0;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif //_SERVER_INNER_H_
|
||||
@@ -0,0 +1,606 @@
|
||||
#ifdef _WIN32
|
||||
// #include <stdarg.h>
|
||||
//#include <iostream>
|
||||
#include <windows.h>
|
||||
typedef int socklen_t;
|
||||
#else //!WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "typedef.h"
|
||||
#include "debug.h"
|
||||
#include "Socket.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CSocket
|
||||
//
|
||||
CSocket::CSocket()
|
||||
{
|
||||
m_bOpen = false;
|
||||
m_skt = 0;
|
||||
}
|
||||
|
||||
CSocket::~CSocket()
|
||||
{
|
||||
int ret = 0;
|
||||
if( IsOpen() ){
|
||||
ret = Close();
|
||||
}
|
||||
|
||||
if( m_skt>0 && ret==0 ){
|
||||
closesocket (m_skt);
|
||||
m_skt = 0;
|
||||
}
|
||||
else{
|
||||
int err = GetLastError();
|
||||
DebugPrint( "Close error code=%d.\n", err );
|
||||
}
|
||||
}
|
||||
|
||||
int CSocket::Close()
|
||||
{
|
||||
if( m_bOpen && m_skt>0 ){
|
||||
m_bOpen = false;
|
||||
return shutdown( m_skt, 0x02 );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CSocket::GetLocalAddr(char *sAddr)
|
||||
{
|
||||
if (!sAddr) return false;
|
||||
|
||||
SOCKADDR_IN addr;
|
||||
#ifdef __MACOSX__
|
||||
UINT nSize = sizeof(addr);
|
||||
#else
|
||||
int nSize = sizeof(addr);
|
||||
#endif
|
||||
if (::getsockname(m_skt,(struct sockaddr*)&addr,(socklen_t*)&nSize)==SOCKET_ERROR)
|
||||
return false;
|
||||
char *pb=(char *)&(addr.sin_addr);
|
||||
|
||||
unsigned b1=(unsigned char)(*pb);
|
||||
unsigned b2=(unsigned char)(*(pb+1));
|
||||
unsigned b3=(unsigned char)(*(pb+2));
|
||||
unsigned b4=(unsigned char)(*(pb+3));
|
||||
sprintf(sAddr,"%d.%d.%d.%d",b1,b2,b3,b4);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSocket::SetOption(int option,const void * valuePtr,unsigned int valueSize)
|
||||
{
|
||||
|
||||
return (::setsockopt(m_skt,IPPROTO_IP,option,(char *)valuePtr,valueSize)==0);
|
||||
}
|
||||
|
||||
int CSocket::SetNonblock( bool bNonblock )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
DWORD fionbio = bNonblock;
|
||||
if( ioctlsocket(m_skt, FIONBIO, &fionbio)==SOCKET_ERROR ){
|
||||
ret = GetLastError();
|
||||
DebugPrint("ioctlsocket Error = %d\n", ret );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CSocket::WaitForReading(int nSeconds )
|
||||
{
|
||||
// SetNonblock( true );
|
||||
|
||||
// DebugPrint( "socket wait for reading.\n" );
|
||||
fd_set rfd;
|
||||
FD_ZERO(&rfd);
|
||||
FD_SET(m_skt,&rfd);
|
||||
|
||||
timeval tv;
|
||||
tv.tv_sec = nSeconds;//等待时间
|
||||
tv.tv_usec = 0;
|
||||
|
||||
int ret;
|
||||
// while( true ){
|
||||
ret = select(m_skt+1, &rfd, NULL, NULL, &tv);
|
||||
// if( ret==0 || ret==SOCKET_ERROR || FD_ISSET(m_skt, &rfd)){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// DebugPrint( "socket wait for reading return %d\n", ret );
|
||||
|
||||
if( ret==1 ){
|
||||
if( !FD_ISSET(m_skt, &rfd) ){
|
||||
// DebugPrint( "SetNonblock\n" );
|
||||
// SetNonblock( false );
|
||||
ret = SOCKET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CUDPSocket
|
||||
//
|
||||
CUDPSocket::CUDPSocket()
|
||||
{
|
||||
m_skt = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (m_skt == INVALID_SOCKET){
|
||||
DebugPrint("Can't open UDP socket\n");
|
||||
m_bOpen = false;
|
||||
int nErrorCode = GetLastError();
|
||||
return;
|
||||
}
|
||||
|
||||
m_bOpen = true;
|
||||
|
||||
m_nPacketLen = 0;
|
||||
m_nCur = 0;
|
||||
}
|
||||
|
||||
CUDPSocket::CUDPSocket(unsigned short nPort,bool bRaw)
|
||||
{
|
||||
if( bRaw ){
|
||||
m_skt = socket (AF_INET,SOCK_RAW,108);
|
||||
}
|
||||
else{
|
||||
m_skt = socket (AF_INET,SOCK_DGRAM,0);
|
||||
}
|
||||
|
||||
if (m_skt == INVALID_SOCKET){
|
||||
DebugPrint("Can't open UDP socket\n");
|
||||
m_bOpen = false;
|
||||
int nErrorCode = GetLastError();
|
||||
return;
|
||||
}
|
||||
|
||||
SOCKADDR_IN local_sin;
|
||||
memset(&local_sin, 0, sizeof(local_sin) );
|
||||
|
||||
local_sin.sin_family = AF_INET;
|
||||
local_sin.sin_port = htons (nPort);
|
||||
local_sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (bind (m_skt,(struct sockaddr *) &local_sin,sizeof (sockaddr)) == SOCKET_ERROR){
|
||||
DebugPrint("Binding Error\n");
|
||||
// Close();
|
||||
return;
|
||||
}
|
||||
|
||||
m_bOpen = true;
|
||||
|
||||
m_nPacketLen = 0;
|
||||
m_nCur = 0;
|
||||
}
|
||||
|
||||
CUDPSocket::CUDPSocket(unsigned int ipAddr,unsigned short nPort,bool bRaw)
|
||||
{
|
||||
if( bRaw ){
|
||||
m_skt = socket (AF_INET,SOCK_RAW,108);
|
||||
}
|
||||
else{
|
||||
m_skt = socket (AF_INET,SOCK_DGRAM,0);
|
||||
}
|
||||
|
||||
if (m_skt == INVALID_SOCKET){
|
||||
DebugPrint("Can't open UDP socket\n");
|
||||
int nError=GetLastError();
|
||||
DebugPrint("CUDPSocket::CUDPSocket Socket Error = %d\n",nError);
|
||||
m_bOpen = false;
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if( SetNonblock( true )!=0 ){
|
||||
return;
|
||||
}
|
||||
*/
|
||||
memset(&ptop, 0, sizeof(ptop) );
|
||||
|
||||
ptop.sin_family=AF_INET;
|
||||
ptop.sin_addr.s_addr=ipAddr;
|
||||
ptop.sin_port=htons(nPort);
|
||||
/*
|
||||
for(int bufLen=0;bufLen<8;bufLen++)
|
||||
ptop.sin_zero[bufLen] = 0;
|
||||
|
||||
SetNonblock( false );
|
||||
*/
|
||||
m_bOpen = true;
|
||||
|
||||
m_nPacketLen = 0;
|
||||
m_nCur = 0;
|
||||
}
|
||||
|
||||
CUDPSocket::CUDPSocket(char *sOtherName,unsigned short nPort,bool bRaw)
|
||||
{
|
||||
CUDPSocket( inet_addr(sOtherName), nPort, bRaw );
|
||||
}
|
||||
|
||||
bool CUDPSocket::Listen(unsigned int nAllowConn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::ReadBlock(char *sBuf,unsigned int nLen )
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
unsigned int nRemain=nLen;
|
||||
char bufffer[MAX_UDP_PACKET_SIZE];
|
||||
|
||||
while (nRemain>0){
|
||||
if (m_nCur>=m_nPacketLen){//需要读报
|
||||
unsigned int nIpAddr;
|
||||
unsigned short nPort;
|
||||
|
||||
if( (m_nPacketLen=ReadFrom(bufffer,MAX_UDP_PACKET_SIZE,nIpAddr,nPort))>0 ){
|
||||
m_nCur=0;
|
||||
}
|
||||
else if( m_nPacketLen<=0 ){
|
||||
DebugPrint( "ReadFrom error, Socket error=%d\n", GetLastError() );
|
||||
}
|
||||
else{
|
||||
return (nLen-nRemain);
|
||||
}
|
||||
}
|
||||
else{//从缓冲区中读取
|
||||
unsigned int nReadLen=((m_nPacketLen-m_nCur)>=nRemain)?nRemain:(m_nPacketLen-m_nCur);
|
||||
memcpy(sBuf+(nLen-nRemain),bufffer+m_nCur,nReadLen);
|
||||
nRemain -= nReadLen;
|
||||
m_nCur += nReadLen;
|
||||
}
|
||||
}
|
||||
return (nLen-nRemain);
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::ReadBlock(char *sBuf,unsigned int nLen, unsigned int &nIpAddr,unsigned short &nPort )
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
unsigned int nRemain=nLen;
|
||||
char bufffer[MAX_UDP_PACKET_SIZE];
|
||||
|
||||
while (nRemain>0){
|
||||
if (m_nCur>=m_nPacketLen){//需要读报
|
||||
if ((m_nPacketLen=ReadFrom(bufffer,MAX_UDP_PACKET_SIZE,nIpAddr,nPort)))
|
||||
m_nCur=0;
|
||||
else return (nLen-nRemain);
|
||||
}
|
||||
else{//从缓冲区中读取
|
||||
unsigned int nReadLen=((m_nPacketLen-m_nCur)>=nRemain)?nRemain:(m_nPacketLen-m_nCur);
|
||||
memcpy(sBuf+(nLen-nRemain),bufffer+m_nCur,nReadLen);
|
||||
nRemain -= nReadLen;
|
||||
m_nCur += nReadLen;
|
||||
}
|
||||
}
|
||||
return (nLen-nRemain);
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::ReadFrom(char *sBuf, unsigned int nLen,unsigned int &nIpAddr,unsigned short &nPort)
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
// SOCKADDR_IN addr;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
UINT addrLen = sizeof(sockAddr);
|
||||
#else
|
||||
int addrLen = sizeof(struct sockaddr);
|
||||
#endif
|
||||
|
||||
int nRead=::recvfrom(m_skt,sBuf,nLen,0,(struct sockaddr *)&sockAddr, (socklen_t*)&addrLen);
|
||||
if (nRead!=SOCKET_ERROR) {
|
||||
#ifdef _WIN32
|
||||
nIpAddr = sockAddr.sin_addr.S_un.S_addr;
|
||||
#else
|
||||
nIpAddr = sockAddr.sin_addr.s_addr;
|
||||
#endif
|
||||
nPort = ntohs(sockAddr.sin_port);
|
||||
|
||||
// DebugPrint("recvfrom %s:%d", inet_ntoa(sockAddr.sin_addr), nPort);
|
||||
}
|
||||
|
||||
// DebugPrint( "UDP Receive %dbytes data.\n", nRead );
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::Peek(char *sBuf, unsigned int nLen)
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
UINT addrLen = sizeof(sockAddr);
|
||||
#else
|
||||
int addrLen = sizeof(sockAddr);
|
||||
#endif
|
||||
|
||||
int nRead=::recvfrom(m_skt,sBuf,nLen,MSG_PEEK,(struct sockaddr *)&sockAddr, (socklen_t*)&addrLen);
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::SendTo(char *sBuf,unsigned int nLen, unsigned int nIpAddr,unsigned short nPort )
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
memset(&sockAddr, 0, sizeof(sockAddr) );
|
||||
|
||||
sockAddr.sin_family=AF_INET;
|
||||
sockAddr.sin_addr.s_addr = nIpAddr;
|
||||
sockAddr.sin_port = htons(nPort);
|
||||
|
||||
// DebugPrint("sendto %s:%d", inet_ntoa(sockAddr.sin_addr), nPort);
|
||||
|
||||
int nWrite = ::sendto(m_skt, (const char *)sBuf, nLen, 0, (struct sockaddr *)&sockAddr, sizeof(sockaddr) );
|
||||
if (nWrite!=SOCKET_ERROR){
|
||||
return nWrite;
|
||||
}
|
||||
else{
|
||||
int nError=GetLastError();
|
||||
DebugPrint("CUDPSocket::Send,Socket error = %d\n",nError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int CUDPSocket::Send(char *sBuf,unsigned int nLen)
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
int nWrite = ::sendto(m_skt, (const char *)sBuf, nLen, 0, (struct sockaddr *)&ptop,sizeof(sockaddr));
|
||||
if (nWrite!=SOCKET_ERROR){
|
||||
return nWrite;
|
||||
}
|
||||
else{
|
||||
int nError=GetLastError();
|
||||
DebugPrint("PUDPSocket::Send,Socket error = %d\n",nError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TCP_NODELAY 0x0001
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CTCPSocket
|
||||
//
|
||||
CTCPSocket::CTCPSocket()
|
||||
{
|
||||
|
||||
if ((m_skt = socket (AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET){
|
||||
DebugPrint("Can't open tcp socket\n");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if( SetNonblock( true )!=0 )
|
||||
return;
|
||||
*/
|
||||
int yes = 1;
|
||||
|
||||
setsockopt( m_skt, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes) );
|
||||
setsockopt( m_skt, SOL_SOCKET, SO_KEEPALIVE, (char *)&yes, sizeof(yes) );
|
||||
setsockopt( m_skt, SOL_SOCKET, SO_REUSEADDR, (char *)0, 0 );
|
||||
setsockopt( m_skt, SOL_SOCKET, SO_OOBINLINE, (char *)&yes, sizeof(yes) );
|
||||
|
||||
#ifdef SO_NOSIGPIPE
|
||||
#ifndef MSG_NOSIGNAL
|
||||
setsockopt( m_skt, SOL_SOCKET, SO_NOSIGPIPE, (char *)&yes, sizeof(yes) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
m_bOpen = true;
|
||||
}
|
||||
|
||||
CTCPSocket::CTCPSocket(unsigned short nPort)
|
||||
{
|
||||
if ((m_skt = socket (AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET){
|
||||
DebugPrint("Can't open tcp socket\n");
|
||||
m_bOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SOCKADDR_IN local_sin;
|
||||
local_sin.sin_family = AF_INET;
|
||||
local_sin.sin_port = htons (nPort);
|
||||
local_sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (bind (m_skt,(struct sockaddr *) &local_sin,sizeof (local_sin)) == SOCKET_ERROR){
|
||||
DebugPrint("Binding Error\n");
|
||||
// Close();
|
||||
return;
|
||||
}
|
||||
m_bOpen = true;
|
||||
}
|
||||
|
||||
|
||||
CTCPSocket::CTCPSocket(char *sOtherName,unsigned short nPort)
|
||||
{
|
||||
|
||||
if ((m_skt = socket (AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET){
|
||||
DebugPrint("Can't open tcp socket\n");
|
||||
m_bOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
int yes = 1;
|
||||
|
||||
setsockopt(m_skt, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes));
|
||||
setsockopt(m_skt, SOL_SOCKET, SO_KEEPALIVE, (char *)&yes, sizeof(yes));
|
||||
setsockopt (m_skt, SOL_SOCKET, SO_REUSEADDR, (char *)0, 0);
|
||||
setsockopt (m_skt, SOL_SOCKET, SO_OOBINLINE, (char *)&yes, sizeof(yes));
|
||||
|
||||
m_bOpen = Connect( inet_addr(sOtherName), nPort );
|
||||
}
|
||||
|
||||
bool CTCPSocket::Listen(unsigned int nAllowConn)
|
||||
{
|
||||
if (listen (m_skt,nAllowConn) == SOCKET_ERROR){
|
||||
DebugPrint("Listening to the client failed.\n");
|
||||
// Close();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTCPSocket::Accept(CTCPSocket *pServerSkt)
|
||||
{
|
||||
sockaddr accept_sin;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
UINT nAcptSinLen = sizeof (accept_sin);
|
||||
#else
|
||||
int nAcptSinLen = sizeof (accept_sin);
|
||||
#endif
|
||||
|
||||
m_skt = accept(pServerSkt->GetSocket(), (struct sockaddr *)&accept_sin, (socklen_t*)&nAcptSinLen);
|
||||
|
||||
if (m_skt == INVALID_SOCKET) {
|
||||
DebugPrint("Accepting connection with client failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bOpen = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTCPSocket::Connect(unsigned int nIpAddr,unsigned short nPort)
|
||||
{
|
||||
if( m_skt==-1 ) return false;
|
||||
|
||||
SetNonblock( true );
|
||||
|
||||
SOCKADDR_IN dest_sin;
|
||||
dest_sin.sin_family = AF_INET;
|
||||
dest_sin.sin_port = htons (nPort);
|
||||
dest_sin.sin_addr.s_addr = nIpAddr;
|
||||
|
||||
int nError = connect( m_skt,(PSOCKADDR)&dest_sin,sizeof (dest_sin));
|
||||
if( nError==SOCKET_ERROR ){
|
||||
nError = WSAGetLastError();
|
||||
#ifdef _WIN32
|
||||
if( nError!=WSAEWOULDBLOCK ){
|
||||
#else
|
||||
if( nError!=EINPROGRESS ){
|
||||
#endif
|
||||
DebugPrint("Connecting to the server connect error. code=%d\n", nError );
|
||||
m_bOpen = false;
|
||||
// closesocket( m_skt );
|
||||
// m_skt = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
fd_set fdWr;
|
||||
FD_ZERO(&fdWr);
|
||||
FD_SET(m_skt,&fdWr);
|
||||
|
||||
timeval tv;
|
||||
tv.tv_sec = 5;//等待5秒钟
|
||||
tv.tv_usec = 0;
|
||||
|
||||
nError = select(m_skt+1, NULL, &fdWr, NULL, &tv);
|
||||
|
||||
if( nError==0 ){
|
||||
DebugPrint("Connecting to the server time out.\n");
|
||||
m_bOpen = false;
|
||||
return false;
|
||||
}
|
||||
else if( nError==SOCKET_ERROR || !FD_ISSET(m_skt, &fdWr) ){
|
||||
nError = WSAGetLastError();
|
||||
DebugPrint("Connecting to the server select error. code=%d\n", nError);
|
||||
m_bOpen = false;
|
||||
// closesocket( m_skt );
|
||||
// m_skt = -1;
|
||||
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
DebugPrint( "Connecting select return %d\n", nError );
|
||||
}
|
||||
}
|
||||
else{
|
||||
DebugPrint( "Tcp connect return %d\n", nError );
|
||||
}
|
||||
|
||||
SetNonblock( false );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int CTCPSocket::ReadBlock(char *sBuf,unsigned int nLen)
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
unsigned int nReturn = recv (m_skt, sBuf, nLen, 0);
|
||||
|
||||
if( nReturn==0 ){
|
||||
DebugPrint( "Socket has been shutdown by remote.\n" );
|
||||
// Close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( nReturn==SOCKET_ERROR ){
|
||||
int err = WSAGetLastError();
|
||||
DebugPrint("Socket error, code=%d\n", err);
|
||||
// Close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DebugPrint( "TCP Receive %dbytes data.\n", nReturn );
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
unsigned int CTCPSocket::Send(char *sBuf,unsigned int nLen)
|
||||
{
|
||||
if (!m_bOpen) return 0;
|
||||
|
||||
unsigned nReturn = send( m_skt, sBuf, nLen, 0 );
|
||||
if (nReturn == SOCKET_ERROR){
|
||||
int err = WSAGetLastError();
|
||||
DebugPrint("Sending data to the client failed. err=%d\n", err);
|
||||
// Close();
|
||||
|
||||
return -1;
|
||||
}
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
void CTCPSocket::GetPeerAddr(char *sAddr)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
UINT size = sizeof(addr);
|
||||
#else
|
||||
int size = sizeof(addr);
|
||||
#endif
|
||||
|
||||
if (getpeername(m_skt,(struct sockaddr *)&addr,(socklen_t*)&size)==SOCKET_ERROR)
|
||||
strcpy(sAddr,"");
|
||||
else{
|
||||
char *pb=(char *)&(addr.sin_addr);
|
||||
unsigned b1=(unsigned char)(*pb);
|
||||
unsigned b2=(unsigned char)(*(pb+1));
|
||||
unsigned b3=(unsigned char)(*(pb+2));
|
||||
unsigned b4=(unsigned char)(*(pb+3));
|
||||
sprintf(sAddr,"%d.%d.%d.%d",b1,b2,b3,b4);
|
||||
}
|
||||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef SocketH
|
||||
#define SocketH
|
||||
|
||||
#define MAX_UDP_PACKET_SIZE 8192
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
typedef unsigned int SOCKET;
|
||||
typedef struct sockaddr SOCKADDR, *PSOCKADDR;
|
||||
#define INVALID_SOCKET (SOCKET)(~0)
|
||||
#define SOCKET_ERROR (-1)
|
||||
#define SOCKADDR_IN sockaddr_in
|
||||
#define IN_ADDR in_addr
|
||||
#define ioctlsocket ioctl
|
||||
#define closesocket close
|
||||
#endif
|
||||
|
||||
class CSocket{
|
||||
protected:
|
||||
SOCKET m_skt;
|
||||
bool m_bOpen;
|
||||
|
||||
public:
|
||||
CSocket();
|
||||
~CSocket();
|
||||
SOCKET GetSocket() {return m_skt;};
|
||||
bool IsOpen(){return m_bOpen;};
|
||||
virtual unsigned int ReadBlock(char *sBuf,unsigned int nLen)=0;
|
||||
virtual bool Listen(unsigned int nAllowConn)=0;
|
||||
virtual unsigned int Send(char *sBuf,unsigned int nLen)=0;
|
||||
virtual int Close();
|
||||
bool GetLocalAddr(char *sAddr);
|
||||
bool SetOption(int option,const void * valuePtr,unsigned int valueSize);
|
||||
int SetNonblock( bool bNonblock );
|
||||
virtual int WaitForReading(int nSeconds);
|
||||
};
|
||||
|
||||
class CUDPSocket:public CSocket{
|
||||
public:
|
||||
CUDPSocket(); //随机端口初始化
|
||||
CUDPSocket(unsigned short nPort,bool bRaw=false);//服务器端初始化
|
||||
CUDPSocket(unsigned int ipAddr,unsigned short nPort,bool bRaw=false);//客户端初始化
|
||||
CUDPSocket(char *sOtherName,unsigned short nPort,bool bRaw=false);//客户端初始化
|
||||
|
||||
virtual bool Listen(unsigned int nAllowConn);
|
||||
virtual unsigned int ReadBlock(char *sBuf,unsigned int nLen);
|
||||
virtual unsigned int ReadBlock(char *sBuf,unsigned int nLen, unsigned int &nIpAddr,unsigned short &nPort);
|
||||
unsigned int ReadFrom(char *sBuf, unsigned int nLen,unsigned int &nIpAddr,unsigned short &nPort);
|
||||
virtual unsigned int Send(char *sBuf,unsigned int nLen);
|
||||
virtual unsigned int SendTo(char *sBuf,unsigned int nLen, unsigned int nIpAddr,unsigned short nPort);
|
||||
virtual unsigned int Peek(char *sBuf, unsigned int nLen);
|
||||
|
||||
protected:
|
||||
sockaddr_in ptop;
|
||||
unsigned int m_nPacketLen,m_nCur;
|
||||
};
|
||||
|
||||
class CTCPSocket:public CSocket{
|
||||
public:
|
||||
CTCPSocket(); //随机端口初始化
|
||||
CTCPSocket(unsigned short nPort);//服务器端初始化
|
||||
CTCPSocket(char *sOtherName,unsigned short nPort);//客户端初始化
|
||||
|
||||
bool Connect(unsigned int ipAddr,unsigned short nPort);
|
||||
virtual bool Listen(unsigned int nAllowConn);
|
||||
bool Accept(CTCPSocket *pServerSkt);
|
||||
virtual unsigned int ReadBlock(char *sBuf,unsigned int nLen);
|
||||
virtual unsigned int Send(char *sBuf,unsigned int nLen);
|
||||
// virtual int Close();
|
||||
void GetPeerAddr(char *sAddr);
|
||||
};
|
||||
#endif //_SOCKET_H_
|
||||
@@ -0,0 +1,286 @@
|
||||
#ifndef commonstructH
|
||||
#define commonstructH
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#else
|
||||
#include "typedef.h"
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
enum EClientType{
|
||||
e_Ac_Windows,
|
||||
e_CZ_Android,
|
||||
e_CZ_iOS,
|
||||
e_Ac_Android,
|
||||
e_Ac_iOS,
|
||||
e_Web,
|
||||
e_Pro_Windows,
|
||||
e_SM_Checker,
|
||||
e_Pro_Lite
|
||||
};
|
||||
|
||||
enum EStyleState{
|
||||
e_OffLine = -2, //下线
|
||||
e_CheckFail, //审核未通过
|
||||
e_Checking, //待审核
|
||||
e_Distribute, //发布
|
||||
e_UnDownload, //未下载
|
||||
e_Downloading, //在下载
|
||||
e_Downloaded //已下载
|
||||
};
|
||||
|
||||
enum EStyleType{
|
||||
e_ST_BEGIN,
|
||||
e_ST_Origin,
|
||||
e_ST_Temp,
|
||||
e_ST_Share,
|
||||
e_ST_END
|
||||
};
|
||||
|
||||
enum ESoundEffectPreset{
|
||||
e_SE_echo,
|
||||
e_SE_distorition,
|
||||
e_SE_reverbMaxium,
|
||||
e_SE_reverbMiddle,
|
||||
e_SE_reverbMinium,
|
||||
e_SE_rotate,
|
||||
e_SE_compressMaxium,
|
||||
e_SE_compressMiddle,
|
||||
e_SE_compressMinium,
|
||||
e_SE_wah,
|
||||
e_SE_phaser,
|
||||
e_SE_EQ
|
||||
};
|
||||
|
||||
enum EPaymentOperation{
|
||||
e_PO_Pay4Basic = 0x01, //基本功能费
|
||||
e_PO_Pay4Compose = 0x02, //保存编曲
|
||||
e_PO_Pay4Midi = 0x04, //导出MIDI
|
||||
e_PO_Pay4Audios = 0x08, //多音轨输出
|
||||
e_PO_Pay4Fonts = 0x10, //多音色库
|
||||
e_PO_End
|
||||
};
|
||||
|
||||
#pragma pack (2)
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// 通道信息
|
||||
typedef struct tagChan{
|
||||
char no; //通道号
|
||||
char prog; //乐器号
|
||||
char vol; //音量
|
||||
|
||||
tagChan(){
|
||||
no = prog = vol = -1;
|
||||
}
|
||||
}TCHAN, *PTCHAN;
|
||||
|
||||
//风格详细信息结构体
|
||||
typedef struct tagStyleDetail{
|
||||
int size;
|
||||
int idAuthor; //作者ID
|
||||
|
||||
short iTempo; //原速
|
||||
short iTimesignature; //节拍 ( 0=4/4, 1=3/4, 2=2/4, 3=6/8 )
|
||||
char type[4]; //风格分类
|
||||
char nSegNum[4]; //伴奏/加花/前奏/尾奏个数
|
||||
|
||||
//以下部分可变长度传输和存储
|
||||
char strAuthor[40]; //作者名称 UTF8
|
||||
char strStyleName[40]; //风格名称 UTF8
|
||||
char strDescription[120]; //风格描述 UTF8
|
||||
|
||||
char aIntroBars[8]; //前奏小节数
|
||||
char aEndingBars[8]; //尾奏小节数
|
||||
char chordRecom[8]; //推荐和声进行
|
||||
|
||||
TCHAN tracks[4][8][16]; //伴奏/加花/前奏/尾奏轨道信息 (前/尾奏0/2/4/6大调 1/3/5/7小调)
|
||||
|
||||
tagStyleDetail(){
|
||||
size = sizeof(tagStyleDetail);
|
||||
idAuthor = iTempo = iTimesignature = 0;
|
||||
memset( type, -1, sizeof(type) );
|
||||
memset( nSegNum, 0, sizeof(nSegNum) );
|
||||
|
||||
memset( strAuthor, 0, sizeof(strAuthor) );
|
||||
memset( strStyleName, 0, sizeof(strStyleName) );
|
||||
memset( strDescription, 0, sizeof(strDescription) );
|
||||
|
||||
memset( aIntroBars, 0, sizeof(aIntroBars) );
|
||||
memset( aEndingBars, 0, sizeof(aEndingBars) );
|
||||
memset( chordRecom, -1, sizeof(chordRecom) );
|
||||
}
|
||||
}TSTYLEDETAIL, *PTSTYLEDETAIL;
|
||||
|
||||
//风格信息结构体
|
||||
typedef struct tagStyleInfo{
|
||||
UINT idStyle; //风格ID
|
||||
short cost; //使用消费
|
||||
short score; //评分 (score/100)10分制
|
||||
int paid; //支付次数
|
||||
int state; //状态
|
||||
|
||||
TSTYLEDETAIL detail; //详细信息
|
||||
|
||||
tagStyleInfo(){
|
||||
idStyle = 0;
|
||||
cost = 0;
|
||||
score = 0;
|
||||
paid = 0;
|
||||
state = 0;
|
||||
}
|
||||
}TSTYLEINFO, *PTSTYLEINFO;
|
||||
|
||||
//制作风格信息结构体
|
||||
typedef struct tagMakeStyleInfo{
|
||||
short price; //购买消费
|
||||
short cost; //使用消费
|
||||
TSTYLEDETAIL detail; //详细信息
|
||||
|
||||
tagMakeStyleInfo(){
|
||||
price = 0;
|
||||
cost = 0;
|
||||
}
|
||||
}TMAKESTYLEINFO, *PMAKETSTYLEINFO;
|
||||
|
||||
//版本结构体
|
||||
typedef struct
|
||||
{
|
||||
WORD majorVersion; //主版本号
|
||||
WORD minorVersion; //次版本号
|
||||
WORD modifyVersion; //修改版本号
|
||||
WORD buildVersion; //编译版本号
|
||||
}TVERSION, *PTVERSION;
|
||||
|
||||
#define MAX_DESCRIB_LENGTH 1024
|
||||
|
||||
//软件信息结构体
|
||||
typedef struct tSoftwareInfo{
|
||||
int size;
|
||||
TVERSION version;
|
||||
UINT nFileSize;
|
||||
UINT tIssueDate;
|
||||
char strDescribe[MAX_DESCRIB_LENGTH];
|
||||
|
||||
tSoftwareInfo(){
|
||||
memset( this, 0, sizeof(tSoftwareInfo) );
|
||||
size = sizeof(tSoftwareInfo);
|
||||
};
|
||||
} TSOFTWAREINFO, *PTSOFTWAREINFO;
|
||||
|
||||
#pragma pack (4)
|
||||
|
||||
//发布风格更新结构体
|
||||
typedef struct tStyleUpdate{
|
||||
UINT idStyle; //风格ID
|
||||
short cost; //使用消费
|
||||
short score; //评分 (score/100)10分制
|
||||
int paid; //支付次数
|
||||
} TSTYLEUPDATE, *PTSTYLEUPDATE;
|
||||
|
||||
|
||||
//账户信息结构体
|
||||
typedef struct tAccountInfo{
|
||||
UINT ID; //用户ID
|
||||
UINT authority; //用户权限
|
||||
int balance; //帐户余额(唱作音符)
|
||||
int pops; //魅力值
|
||||
int fans; //粉丝数
|
||||
int songs; //歌曲数
|
||||
int vipPeriod; //VIP时长:-1=终身 0=非VIP 其它=vip剩余秒数
|
||||
|
||||
tAccountInfo(){
|
||||
memset( this, 0, sizeof(tAccountInfo) );
|
||||
};
|
||||
}TACCOUNTINFO, *PTACCOUNTINFO;
|
||||
|
||||
//用户信息结构体
|
||||
typedef struct tUserInfo{
|
||||
char strUserName[32];
|
||||
char strPassword[80];
|
||||
char strNickName[32];
|
||||
char strIconFile[32];
|
||||
TACCOUNTINFO accountInfo; //账户信息
|
||||
int ownStyleNum; //已购买风格数
|
||||
int arrStyleId[16]; //已购买风格ID数组
|
||||
|
||||
tUserInfo(){
|
||||
memset( strUserName, 0, 32 );
|
||||
memset( strPassword, 0, 80 );
|
||||
memset( strNickName, 0, 32 );
|
||||
memset( strIconFile, 0, 32 );
|
||||
memset( arrStyleId, 0, 16 );
|
||||
ownStyleNum = 0;
|
||||
};
|
||||
}TUSERINFO,*PTUSERINFO;
|
||||
|
||||
//字符串对结构体
|
||||
typedef struct tStringPair{
|
||||
char str1[320];
|
||||
char str2[640];
|
||||
|
||||
tStringPair(){
|
||||
memset( str1, 0, 320 );
|
||||
memset( str2, 0, 640 );
|
||||
}
|
||||
} TSTRINGPAIR, *PTSTRINGPAIR;
|
||||
|
||||
//上传歌曲信息结构体
|
||||
typedef struct tSongInfo{
|
||||
int size; //结构大小
|
||||
char strSongName[64]; //歌曲名
|
||||
int iTempo; //速度
|
||||
char iTS; //节拍
|
||||
char iCreation; //创作类型 (1:原创 3:改编)
|
||||
char iSubmit; //提交审核状态(0:不提交,1:自动提交)
|
||||
char iSingerType; //演唱人类别 (1:男;2:女;3:组合;4:其他;0:未知)
|
||||
char strSinger[32]; //演唱
|
||||
char strOriginal[32]; //原唱
|
||||
char strLyricist[32]; //作词
|
||||
char strComposer[32]; //作曲
|
||||
char strArranger[32]; //编曲
|
||||
char iMusicStyle[4]; //曲风
|
||||
UINT aStyleIDs[32]; //使用的风格ID
|
||||
char strDescription[640];//歌曲描述
|
||||
char* strLyric; //歌词
|
||||
char* strMp3Name; //mp3临时文件
|
||||
char* strIconName; //封面临时文件
|
||||
|
||||
//上传工程文件
|
||||
UINT cpjVersion; //工程版本号
|
||||
int cpjPrice; //下载收费
|
||||
char* strCpjName; //工程文件名
|
||||
|
||||
tSongInfo(){
|
||||
memset( this, 0, sizeof(tSongInfo) );
|
||||
memset( iMusicStyle, -1, 4 );
|
||||
size = sizeof(tSongInfo);
|
||||
};
|
||||
|
||||
~tSongInfo(){
|
||||
if( strLyric )
|
||||
delete[] strLyric;
|
||||
if( strMp3Name )
|
||||
delete[] strMp3Name;
|
||||
if( strIconName )
|
||||
delete[] strIconName;
|
||||
if( strCpjName )
|
||||
delete[] strCpjName;
|
||||
};
|
||||
} TSONGINFO, *PTSONGINFO;
|
||||
|
||||
//上传歌曲返回分享信息结构
|
||||
typedef struct tShareInfo{
|
||||
UINT idSong; //歌曲ID
|
||||
char strSongURL[256]; //歌曲文件URL
|
||||
char strCoverURL[256]; //歌曲封面URL
|
||||
|
||||
tShareInfo(){
|
||||
memset( this, 0, sizeof(tShareInfo) );
|
||||
};
|
||||
} TSHAREINFO, *PTSHAREINFO;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif //_COMMONSTRUCT_H_
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
//#include <string>
|
||||
//#include <iostream>
|
||||
#include <stdlib.h>
|
||||
// #include <windows.h>
|
||||
|
||||
/*******************************************************
|
||||
int DebugPrint(const char * fmt, ...)
|
||||
功能描述:
|
||||
提供类似于printf的调试打印语句
|
||||
********************************************************/
|
||||
int DebugPrint(const char * fmt, ...)
|
||||
{
|
||||
char sDebug[10240];
|
||||
char tbuffer[9];
|
||||
va_list vaParams;
|
||||
|
||||
time_t now;
|
||||
time(&now);
|
||||
strftime(sDebug, sizeof(sDebug), "[%Y-%m-%d %H:%M:%S]",localtime(&now));
|
||||
|
||||
va_start(vaParams,fmt);
|
||||
vsprintf(sDebug+strlen(sDebug),fmt,vaParams);
|
||||
|
||||
// OutputDebugString( sDebug );
|
||||
printf( "%s\n", sDebug );
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _DEBUG_H_
|
||||
#define _DEBUG_H_
|
||||
|
||||
#ifdef __MACOSX__
|
||||
#if DEBUG
|
||||
#define DebugPrint printf
|
||||
#else
|
||||
#define DebugPrint
|
||||
#endif
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int DebugPrint( const char * fmt, ... );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TRACE
|
||||
#define TRACE DebugPrint
|
||||
#endif
|
||||
|
||||
#endif //_DEBUG_H_
|
||||
@@ -0,0 +1,348 @@
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#else //!WIN32
|
||||
#include <pthread.h>
|
||||
#include <sys/time.h>
|
||||
#include <semaphore.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "typedef.h"
|
||||
#include "debug.h"
|
||||
#include "thread.h"
|
||||
|
||||
|
||||
CSema::CSema(const char *sName, unsigned int nInit, bool bCreate)
|
||||
{
|
||||
m_bCreate = bCreate;
|
||||
if (!m_bCreate)
|
||||
return;
|
||||
|
||||
#ifdef _WIN32
|
||||
m_hSema = CreateSemaphore(NULL,nInit,0xffff,NULL);
|
||||
if (!m_hSema){
|
||||
#else
|
||||
semCount = nInit;
|
||||
if( pthread_mutex_init(&mutex, NULL) || pthread_cond_init(&condition, NULL) ){
|
||||
#endif
|
||||
DebugPrint("Create semaphore error, errno=%d\n", errno );
|
||||
}
|
||||
}
|
||||
|
||||
CSema::~CSema()
|
||||
{
|
||||
if (!m_bCreate)
|
||||
return;
|
||||
int rc = 0;
|
||||
#ifdef _WIN32
|
||||
if( !(rc=CloseHandle(m_hSema)) ){
|
||||
#else
|
||||
rc = pthread_mutex_destroy(&mutex);
|
||||
if( rc ){
|
||||
DebugPrint( "destroy mutex ret %d\n", rc );
|
||||
}
|
||||
rc = pthread_cond_destroy(&condition);
|
||||
if( rc ){
|
||||
#endif
|
||||
DebugPrint("delete semaphore error %d\n", rc );
|
||||
}
|
||||
}
|
||||
|
||||
int CSema::ActP(DWORD dwTimeout)
|
||||
{
|
||||
if (!m_bCreate)
|
||||
return -1;
|
||||
|
||||
int ret;
|
||||
#ifdef _WIN32
|
||||
ret = WaitForSingleObject(m_hSema, dwTimeout);
|
||||
if( ret==WAIT_TIMEOUT ){
|
||||
#else
|
||||
if( dwTimeout==INFINITE ){
|
||||
if( (ret=pthread_mutex_lock(&mutex))==0 ){
|
||||
while( semCount<=0 ){
|
||||
if( (ret=pthread_cond_wait(&condition, &mutex)) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !ret )
|
||||
semCount--;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
else{
|
||||
DebugPrint( "lock mutex error %d.\n", ret );
|
||||
}
|
||||
}
|
||||
else{
|
||||
if( (ret = pthread_mutex_lock(&mutex))==0 ){
|
||||
timeval tv;
|
||||
// struct timezone tz;
|
||||
timespec tm;
|
||||
gettimeofday (&tv , /*&tz*/NULL);
|
||||
|
||||
tm.tv_sec = tv.tv_sec + dwTimeout/1000 + ( tv.tv_usec + (dwTimeout%1000)*1000 ) / 1000000;
|
||||
tm.tv_nsec = 1000 * ( ( tv.tv_usec + (dwTimeout%1000)*1000 ) % 1000000 );
|
||||
|
||||
while( semCount<=0 ){
|
||||
if( (ret=pthread_cond_timedwait( &condition, &mutex, &tm )) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !ret )
|
||||
semCount--;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
}
|
||||
else{
|
||||
DebugPrint( "Lock mutext error %d.\n", ret );
|
||||
}
|
||||
}
|
||||
|
||||
if( ret==ETIMEDOUT ){
|
||||
#endif
|
||||
// DebugPrint("WaitforSingleObject timeout!\n");
|
||||
return 1;
|
||||
}
|
||||
else if( ret!=0 ){
|
||||
DebugPrint( "sema wait error. errno=%d\n", errno );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CSema::ActV()
|
||||
{
|
||||
if (!m_bCreate)
|
||||
return;
|
||||
#ifdef _WIN32
|
||||
if (!ReleaseSemaphore(m_hSema,1,NULL)){
|
||||
#else
|
||||
int rc;
|
||||
if( (rc = pthread_mutex_lock(&mutex)) ){
|
||||
DebugPrint("mutex lock error.errno=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
if( semCount<=0 )
|
||||
semCount ++;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
rc = pthread_cond_signal(&condition);
|
||||
|
||||
if( rc ){
|
||||
#endif
|
||||
DebugPrint("sema post error.errno=%d\n", errno);
|
||||
}
|
||||
}
|
||||
|
||||
CMutexLock::CMutexLock(bool bCreate)
|
||||
{
|
||||
m_psmMut = new CSema( NULL, 1, bCreate );
|
||||
|
||||
m_psmMut->ActP();
|
||||
}
|
||||
|
||||
CMutexLock::CMutexLock(CSema * pSema, DWORD dwTimeOut)
|
||||
{
|
||||
m_psmMut = pSema;
|
||||
|
||||
m_psmMut->ActP(dwTimeOut);
|
||||
}
|
||||
|
||||
CMutexLock::~CMutexLock()
|
||||
{
|
||||
if( m_psmMut!=NULL )
|
||||
m_psmMut->ActV();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CThread::CThread(unsigned int stackSize, EPriority priorityLevel)
|
||||
#ifndef _WIN32
|
||||
: m_smSuspend( NULL, 0 ), m_smSleep( NULL, 0 )
|
||||
#endif
|
||||
{
|
||||
if(stackSize<=0){
|
||||
DebugPrint("CThread 输入参数不正确\n");
|
||||
}
|
||||
|
||||
m_bSuspend = true;
|
||||
m_bExit = false;
|
||||
m_nStackSize = stackSize;
|
||||
|
||||
// DebugPrint("create CThread with stacksize of %d\n", stackSize);
|
||||
#ifdef _WIN32
|
||||
m_hThreadHandle = (HANDLE)_beginthreadex(NULL, stackSize, MainFunction,
|
||||
this, CREATE_SUSPENDED, &m_nThreadId);
|
||||
// m_bSuspend = true;
|
||||
#else
|
||||
pthread_attr_init(&m_tAttr);
|
||||
pthread_attr_setstacksize( &m_tAttr, stackSize );
|
||||
//pthread_attr_setschedpolicy( &m_tAttr, SCHED_RR ); //SCHED_RR 或者 SCHED_FIFO,程序必须要在超级用户下运行,否则失败
|
||||
m_hThreadHandle = 0;
|
||||
// SetPriority(e_LowestPriority);
|
||||
// DebugPrint( "Set thread attributes.\n" );
|
||||
//pthread_create( &m_hThreadHandle, &m_tAttr, MainFunction, this );
|
||||
// DebugPrint("CThread constructure finished.\n" );
|
||||
#endif
|
||||
|
||||
SetPriority(priorityLevel);
|
||||
}
|
||||
|
||||
CThread::~CThread()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if( m_hThreadHandle != NULL ){
|
||||
DWORD dwExitCode = 0;
|
||||
if( GetExitCodeThread(m_hThreadHandle, &dwExitCode)==0){
|
||||
DebugPrint("PThread::~PThread,GetExitCode failed errorcode=%d\n", GetLastError());
|
||||
}
|
||||
else if( dwExitCode==STILL_ACTIVE ){
|
||||
if (WAIT_OBJECT_0 != WaitForSingleObject(m_hThreadHandle,100)){
|
||||
TerminateThread(m_hThreadHandle, 2);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(m_hThreadHandle);
|
||||
}
|
||||
#else
|
||||
pthread_join( m_hThreadHandle, NULL );
|
||||
pthread_attr_destroy( &m_tAttr );
|
||||
#endif
|
||||
}
|
||||
|
||||
void CThread::ExitThread()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
_endthreadex(0);
|
||||
#else
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
unsigned int __stdcall CThread::MainFunction(void *threadPtr)
|
||||
#else
|
||||
void* CThread::MainFunction(void *threadPtr)
|
||||
#endif
|
||||
{
|
||||
if(threadPtr==NULL){
|
||||
DebugPrint("CThread::MainFunction threadPtr is NULL!\n");
|
||||
}
|
||||
else{
|
||||
CThread *thread = (CThread *)threadPtr;
|
||||
// DebugPrint("Get CThread object 0x%X\n", (long)thread );
|
||||
thread->Main();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
return 0;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CThread::Suspend()
|
||||
{
|
||||
if (m_bSuspend) return;
|
||||
|
||||
// DebugPrint( "Suspend in.\n" );
|
||||
m_bSuspend = true;
|
||||
#ifdef _WIN32
|
||||
SuspendThread(m_hThreadHandle);
|
||||
#else
|
||||
m_smSuspend.ActP();
|
||||
#endif
|
||||
|
||||
// DebugPrint( "Suspend out.\n" );
|
||||
}
|
||||
|
||||
void CThread::Terminate()
|
||||
{
|
||||
if (m_bExit) return;
|
||||
|
||||
m_bExit = true;
|
||||
}
|
||||
|
||||
void CThread::Resume()
|
||||
{
|
||||
if (!m_bSuspend) return;
|
||||
|
||||
m_bSuspend = false;
|
||||
|
||||
// DebugPrint( "Resume call.\n" );
|
||||
|
||||
#ifdef _WIN32
|
||||
ResumeThread(m_hThreadHandle);
|
||||
#else
|
||||
if( !m_hThreadHandle ){
|
||||
int err = pthread_create( &m_hThreadHandle, &m_tAttr, MainFunction, this );
|
||||
if(err!=0)
|
||||
DebugPrint( "create pthread return %d\n", err );
|
||||
}
|
||||
else{
|
||||
m_smSuspend.ActV();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void CThread::SetPriority(EPriority priorityLevel)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int nPrior;
|
||||
|
||||
switch (priorityLevel){
|
||||
case e_LowestPriority:
|
||||
nPrior = THREAD_PRIORITY_LOWEST;
|
||||
break;
|
||||
case e_LowPriority:
|
||||
nPrior = THREAD_PRIORITY_BELOW_NORMAL;
|
||||
break;
|
||||
case e_NormalPriority:
|
||||
nPrior = THREAD_PRIORITY_NORMAL;
|
||||
break;
|
||||
case e_HighPriority:
|
||||
nPrior = THREAD_PRIORITY_ABOVE_NORMAL;
|
||||
break;
|
||||
case e_HighestPriority:
|
||||
nPrior = THREAD_PRIORITY_TIME_CRITICAL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!SetThreadPriority(m_hThreadHandle,nPrior)) {
|
||||
#else
|
||||
int policy;
|
||||
pthread_attr_getschedpolicy( &m_tAttr, &policy );
|
||||
int max = sched_get_priority_max( policy );
|
||||
int min = sched_get_priority_min( policy );
|
||||
|
||||
sched_param sp;
|
||||
pthread_attr_getschedparam( &m_tAttr, &sp );
|
||||
sp.sched_priority = priorityLevel * (max-min) / (e_NumPriorities-1) + 1;
|
||||
|
||||
if( -1==pthread_attr_setschedparam(&m_tAttr, &sp) ){
|
||||
#endif
|
||||
DebugPrint("set priority failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void CThread::Sleep(DWORD dwMilliseconds)
|
||||
{
|
||||
// DebugPrint( "Sleep %dms\n", dwMilliseconds );
|
||||
#ifdef _WIN32
|
||||
::Sleep(dwMilliseconds);
|
||||
#else
|
||||
m_smSleep.ActP( dwMilliseconds );
|
||||
#endif
|
||||
// DebugPrint( "Sleep %dms over\n", dwMilliseconds );
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
#ifndef threadH
|
||||
#define threadH
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
//#include <process.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include "typedef.h"
|
||||
#endif
|
||||
|
||||
#ifndef INFINITE
|
||||
#define INFINITE 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
//////////////////////////////
|
||||
//
|
||||
// 信号量
|
||||
//
|
||||
class CSema
|
||||
{
|
||||
protected:
|
||||
bool m_bCreate;// 用来控制是否生成信号量,缺省情况下生成。
|
||||
#ifdef _WIN32
|
||||
HANDLE m_hSema;
|
||||
/*#elif defined __MACOSX__
|
||||
sem_t* m_pSema;
|
||||
char m_sName[16];
|
||||
static int m_smNo;
|
||||
#else
|
||||
sem_t m_hSema;
|
||||
*/
|
||||
#else
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t condition;
|
||||
int semCount;
|
||||
#endif
|
||||
|
||||
public:
|
||||
CSema(const char *sName, unsigned int nInit, bool bCreate=true);
|
||||
~CSema();
|
||||
int ActP(DWORD dwTimeOut = INFINITE); // 等待状态
|
||||
void ActV(); // 非等待状态
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
//
|
||||
// 互斥量
|
||||
//
|
||||
class CMutexLock
|
||||
{
|
||||
protected:
|
||||
CSema * m_psmMut;
|
||||
public:
|
||||
CMutexLock(bool bCreate=true);
|
||||
CMutexLock(CSema * pSema, DWORD dwTimeOut = INFINITE);
|
||||
~CMutexLock();
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
//
|
||||
// 线程类
|
||||
//
|
||||
class CThread
|
||||
{
|
||||
public:
|
||||
enum EPriority {
|
||||
e_LowestPriority, // 其它所有线程都停止时运行
|
||||
e_LowPriority, // 运行频率大约为普通优先级一半
|
||||
e_NormalPriority, // 普通优先级
|
||||
e_HighPriority, // 运行频率大约为普通优先级一倍
|
||||
e_HighestPriority, // 独占CPU方式运行
|
||||
e_NumPriorities
|
||||
};
|
||||
protected:
|
||||
bool m_bSuspend;
|
||||
bool m_bExit;
|
||||
int m_nStackSize;
|
||||
unsigned int m_nThreadId;
|
||||
|
||||
void ExitThread();//线程本身要求退出
|
||||
#ifdef _WIN32
|
||||
HANDLE m_hThreadHandle;
|
||||
static unsigned int __stdcall MainFunction(void *threadPtr);
|
||||
#else
|
||||
pthread_t m_hThreadHandle;
|
||||
pthread_attr_t m_tAttr;
|
||||
bool m_bStart;
|
||||
CSema m_smSuspend;
|
||||
CSema m_smSleep;
|
||||
|
||||
static void* MainFunction(void *threadPtr);
|
||||
unsigned long CompPSOSPrio(EPriority nPrioLevel);
|
||||
#endif
|
||||
|
||||
public:
|
||||
CThread(
|
||||
unsigned stackSize, // Size of stack to use for thread.
|
||||
EPriority priorityLevel = e_NormalPriority // Initial priority of thread.
|
||||
);
|
||||
|
||||
~CThread();
|
||||
|
||||
virtual void Main()=0;
|
||||
virtual void Suspend();
|
||||
virtual void Resume();
|
||||
virtual void Terminate();
|
||||
virtual bool IsTerminated() const { return m_bExit; };
|
||||
virtual bool IsSuspended() const { return m_bSuspend; };
|
||||
virtual void SetPriority(EPriority priorityLevel);
|
||||
virtual void Sleep(DWORD dwMilliseconds);
|
||||
//HANDLE GetThreadID(){return m_hThreadHandle;};
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE GetThreadID(){return m_hThreadHandle;};
|
||||
#else
|
||||
unsigned long GetThreadID(){return m_hThreadHandle;};
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif //_THREAD_H_
|
||||
@@ -0,0 +1,119 @@
|
||||
#ifndef _TYPE_DEF_H_
|
||||
#define _TYPE_DEF_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
#define DLLAPI __stdcall
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#include <wtypes.h>
|
||||
#endif
|
||||
|
||||
typedef unsigned __int64 QWORD;
|
||||
#else //!_WIN32
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define DLLAPI
|
||||
|
||||
#define WINAPI
|
||||
#define WINAPIV
|
||||
#define CALLBACK
|
||||
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint16_t WORD, USHORT;
|
||||
typedef uint32_t DWORD;
|
||||
typedef uint64_t QWORD;
|
||||
typedef uint32_t UINT, UINT_PTR;
|
||||
typedef int INT;
|
||||
typedef long LONG;
|
||||
typedef double DOUBLE;
|
||||
|
||||
typedef BYTE *PBYTE, *LPBYTE;
|
||||
typedef void VOID, *PVOID, *LPVOID;
|
||||
|
||||
#ifndef __OBJC__
|
||||
typedef int BOOL;
|
||||
#endif //_OBJC_
|
||||
|
||||
#define LOBYTE(a) (BYTE)(a)
|
||||
#define HIBYTE(a) (BYTE)((a)>>8)
|
||||
#define LOWORD(a) (WORD)(a)
|
||||
#define HIWORD(a) (WORD)((a)>>16)
|
||||
#define MAKEWORD(a,b) (WORD)(((a)&0xff)|((b)<<8))
|
||||
#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16))
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif //FALSE
|
||||
|
||||
#ifndef S_OK
|
||||
#define S_OK ((HRESULT)0x00000000L)
|
||||
#define S_FALSE ((HRESULT)0x00000001L)
|
||||
#define E_FAIL ((HRESULT)0x80004005L)
|
||||
#endif //S_OK
|
||||
|
||||
#ifndef IN
|
||||
#define IN
|
||||
#define OUT
|
||||
#endif //IN
|
||||
|
||||
#ifndef WM_USER
|
||||
#define WM_USER 0x0400
|
||||
#endif //WN_USER
|
||||
|
||||
typedef void *HANDLE;
|
||||
typedef HANDLE HWND;
|
||||
typedef LONG HRESULT;
|
||||
|
||||
#ifndef _HFILE_DEFINED
|
||||
#define _HFILE_DEFINED
|
||||
typedef INT HFILE;
|
||||
#endif // !_HFILE_DEFINED
|
||||
|
||||
#ifndef _LPWORD_DEFINED
|
||||
#define _LPWORD_DEFINED
|
||||
typedef WORD *LPWORD;
|
||||
#endif // !_LPWORD_DEFINED
|
||||
|
||||
#ifndef _LPDWORD_DEFINED
|
||||
#define _LPDWORD_DEFINED
|
||||
typedef DWORD *LPDWORD;
|
||||
#endif // !_LPDWORD_DEFINED
|
||||
|
||||
#ifndef _WPARAM_DEFINED
|
||||
#define _WPARAM_DEFINED
|
||||
typedef uint32_t WPARAM;
|
||||
typedef long LPARAM;
|
||||
typedef long LRESULT;
|
||||
#endif //_WPARAM_DEFINED
|
||||
|
||||
//NDK下统一用UTF8编码
|
||||
typedef char CHAR;
|
||||
typedef /* [string] */ CHAR *LPSTR;
|
||||
typedef /* [string] */ const CHAR *LPCSTR;
|
||||
|
||||
typedef char WCHAR;
|
||||
typedef WCHAR *LPWSTR, *PWSTR;
|
||||
typedef const WCHAR *LPCWSTR, *PCWSTR;
|
||||
|
||||
typedef unsigned char UCHAR;
|
||||
|
||||
void PostMessage( HWND hWnd, int uMsg, WPARAM wParam, LPARAM lParam );
|
||||
//void GetRootPath( char* path, int& size );
|
||||
inline int GetLastError(){ return errno; };
|
||||
#ifndef WSAGetLastError
|
||||
#define WSAGetLastError GetLastError
|
||||
#endif
|
||||
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#endif //_TYPE_DEF_H_
|
||||
Reference in New Issue
Block a user