📄 charpackets.cpp.svn-base
字号:
BYTE hairstyle = GETBYTE((*P), 2 );
BYTE face = GETBYTE((*P), 3 );
string newname = (char*)&P->Buffer[7];
MYSQL_RES *result;
result = DB->QStore("SELECT id FROM characters WHERE account_name='%s'", thisclient->username);
if(result==NULL) return false;
if ( mysql_num_rows( result ) == 5 )
{
BEGINPACKET( pak, 0x713 );
ADDWORD ( pak, 4 );
thisclient->SendPacket( &pak );
DB->QFree( );
return true;
}
DB->QFree( );
result = DB->QStore("SELECT id FROM characters WHERE char_name='%s'", newname.c_str());
if(result==NULL) return false;
if ( mysql_num_rows( result ) > 0 )
{
BEGINPACKET( pak, 0x713);
ADDWORD ( pak, 2 );
thisclient->SendPacket( &pak );
DB->QFree( );
return true;
}
DB->QFree( );
if(!DB->QExecute("INSERT INTO characters (account_name, char_name, face, hairStyle, sex) VALUES('%s','%s',%i,%i,%i)", thisclient->username, newname.c_str(), face, hairstyle, sex))
return false;
unsigned int mid = (unsigned)mysql_insert_id( DB->Mysql );
MYSQL_ROW row;
if(!DB->QExecute("INSERT INTO items VALUES(%i,29,3,0,40,100,3,1,0,0,0,0)", mid))
return false;
if(!DB->QExecute("INSERT INTO items VALUES(%i,29,5,0,40,100,6,1,0,0,0,0)", mid))
return false;
if(!DB->QExecute("INSERT INTO items VALUES(%i,1,8,0,40,100,7,1,0,0,0,0)", mid))
return false;
if(sex==0)
if(!DB->QExecute("INSERT INTO items VALUES(%i,221,2,0,40,100,12,1,0,0,0,0)", mid))
return false;
else
if(!DB->QExecute("INSERT INTO items VALUES(%i,222,2,0,40,100,12,1,0,0,0,0)", mid))
return false;
BEGINPACKET( pak, 0x713 );
ADDWORD ( pak, 0 );
thisclient->SendPacket( &pak );
return true;
}
// Connect WorldServer
bool CCharServer::pakWSReady ( CCharClient* thisclient, CPacket* P )
{
if(thisclient->isLoggedIn) return false;
if(GETDWORD((*P),0) != Config.CharPass )
{
Log( MSG_HACK, "WorldServer Tried to connect CharServer with wrong password ");
return true;
}
thisclient->userid = GETDWORD((*P), 4); //our channelid
thisclient->accesslevel = 0xffff; //this will identify thisclient as channel
// add channel
CChanels* newchannel = new (nothrow) CChanels;
if(newchannel==NULL)
return false;
newchannel->id = GETDWORD((*P), 4);
newchannel->ip = inet_ntoa( thisclient->clientinfo.sin_addr );
newchannel->port = GETWORD((*P),8 );
Log( MSG_INFO, "Channel #%i connected from ip %s", newchannel->id, newchannel->ip );
// Connect to charserver
newchannel->sock = socket( AF_INET, SOCK_STREAM, 0 );
if (newchannel->sock == INVALID_SOCKET)
{
Log( MSG_WARNING, "Could not access worldserver IP: %s , Port: %i", newchannel->ip, newchannel->port );
delete newchannel;
return false;
}
struct sockaddr_in ain;
ain.sin_family = AF_INET;
ain.sin_addr.s_addr = thisclient->clientinfo.sin_addr.s_addr;
ain.sin_port = htons( newchannel->port );
memset(&(ain.sin_zero), '\0', 8);
if ( connect( newchannel->sock , (SOCKADDR*) &ain, sizeof(ain) ) == SOCKET_ERROR)
{
Log( MSG_WARNING, "Could not access worldserver IP: %s , Port: %i", newchannel->ip , newchannel->port );
delete newchannel;
return false;
}
ChannelList.push_back( newchannel );
thisclient->isLoggedIn = true;
BEGINPACKET( pak, 0x500 );
ADDDWORD ( pak, Config.WorldPass );
cryptPacket( (char*)&pak, NULL );
send( newchannel->sock, (char*)&pak, pak.Size, 0 );
return true;
}
// Login Connected
bool CCharServer::pakLoginConnected( CCharClient* thisclient, CPacket* P )
{
if(thisclient->isLoggedIn) return false;
if(GETDWORD((*P),0) != Config.CharPass )
{
Log( MSG_HACK, "LoginServer Tried to connect CharServer with wrong password ");
return true;
}
thisclient->isLoggedIn = true;
return true;
}
// Return to char select
bool CCharServer::pakWSCharSelect ( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
Log( MSG_INFO, "World server requested char select" );
DWORD userid = GETDWORD( (*P), 0 );
CCharClient* otherclient = GetClientByUserID( userid );
if(otherclient==NULL)
{
Log(MSG_WARNING, "Invalid userid: %i", userid );
return true;
}
BEGINPACKET( pak, 0x71c );
ADDBYTE ( pak, 0x00 );
otherclient->SendPacket( &pak );
Log( MSG_INFO, "Client returning to char select" );
RESETPACKET( pak, 0x505 );
ADDDWORD( pak, thisclient->userid );
cryptPacket( (char*)&pak, NULL );
CChanels* thischannel = GetChannelByID( thisclient->channel );
if(thischannel!=NULL)
send( thischannel->sock, (char*)&pak, pak.Size, 0 );
return true;
}
// ???
bool CCharServer::pak7e5 ( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
BYTE action = GETBYTE((*P),0);
switch(action)
{
case 0x03:
BEGINPACKET( pak, 0x7e5 );
ADDBYTE ( pak, 0x01 );
ADDWORD ( pak, 0x0000 );
thisclient->SendPacket( &pak );
break;
default:
Log( MSG_WARNING,"Unknown 7e5 action %i",action);
}
return true;
}
// Create a chatroom?
bool CCharServer::pakChatrooms ( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
return true;
}
// delete/resurect character
bool CCharServer::pakDeleteChar( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
short int action = GETBYTE((*P), 1 );
unsigned long int DeleteTime = 0;
switch(action)
{
case 0x00://Resurect
{
DeleteTime = 0;
if(!DB->QExecute(" UPDATE characters SET deletetime=0 WHERE char_name='%s'",
(char*)&P->Buffer[2] ))
return false;
}
break;
case 0x01://Delete
{
DeleteTime = GetServerTime( ) + Config.DeleteTime;
if(!DB->QExecute(" UPDATE characters SET deletetime=%i WHERE char_name='%s'",
DeleteTime, (char*)&P->Buffer[2] ))
return false;
}
break;
}
BEGINPACKET( pak, 0x714 );
if(DeleteTime > 0 )
{
ADDDWORD ( pak, Config.DeleteTime );
}
else
{
ADDDWORD ( pak, 0x00000000 );
}
ADDSTRING ( pak, (char*)&P->Buffer[2] );
ADDBYTE ( pak, 0x00 );
thisclient->SendPacket( &pak );
return true;
}
bool CCharServer::pakUpdateLevel( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
WORD charid = GETWORD((*P),0);
WORD level = GETWORD((*P),2);
for(UINT i=0;i<ClientList.size();i++)
{
CCharClient* player = (CCharClient*) ClientList.at(i);
if(player->charid==charid)
{
player->level = level;
break;
}
}
return true;
}
// Disconnect client from char/world server
bool CCharServer::pakLoginDSClient( CCharClient* thisclient, CPacket* P )
{
if(!thisclient->isLoggedIn) return false;
BYTE action = GETBYTE((*P),0);
switch(action)
{
case 1:
{
unsigned int userid = GETDWORD ((*P), 1);
CCharClient* otherclient = GetClientByUserID( userid );
if(otherclient==NULL)
{
Log( MSG_WARNING, "Userid '%u' is not online", userid );
return true;
}
otherclient->isLoggedIn = false;
otherclient->isActive = false;
BEGINPACKET( pak, 0x502 );
ADDBYTE ( pak, 1 );
ADDDWORD ( pak, userid );
ADDBYTE ( pak, 0x00 );
cryptPacket( (char*)&pak, NULL );
CChanels* thischannel = GetChannelByID( otherclient->channel );
if(thischannel!=NULL)
send( thischannel->sock, (char*)&pak, pak.Size, 0 );
}
break;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -