www.pudn.com > 天堂1服务端模拟程序.rar > GS_Attack.cpp


/* 
Copyright (C) 2004  freeplay.dk 
 
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. 
 
You may contact me for further information on admin@freeplay.dk 
*/ 
 
#define WIN32_LEAN_AND_MEAN 
 
// disable map warnings for std::map 
#pragma warning (disable: 4786) 
#pragma warning (disable: 4788) 
 
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include "GS_Attack.h" 
#include "resource.h" 
#include "Logging.h" 
#include "CConnection.h" 
#include "Types.h" 
#include "OpCodes.h" 
#include "Database.h" 
#include "ComWindows.h" 
#include "Logging.h" 
 
#include "Gameserver.h" 
 
#include "LoginMap.h" 
#include "CharMap.h" 
#include "ObjectsMultimap.h" 
 
using namespace std; 
 
//******************************************* 
// class defines 
//******************************************* 
extern database logindb; 
extern ComWindows com; 
extern LoginMap dblmap; 
extern charmap chm; 
extern objects obj; 
extern GameServer gs; 
 
void GS_Attack::requestAttack(DWORD ptr, char * data) 
{ 
	CConnection* c = reinterpret_cast  (ptr); 
	char			cip[15]; 
	unsigned int	cp = 0; 
	c->PeerInfo (&cip[0], 15, &cp); 
 
	unsigned long myobj = chm.getObjectid(cp); 
 
	unsigned long targetid = *((unsigned long*)&data[0]); 
	int16 targetx = *((int16*)&data[sizeof(targetid)]); 
	int16 targety = *((int16*)&data[sizeof(targetid)+sizeof(targetx)]); 
 
	char bufatk[24]; 
	char* buf_ptr = bufatk; 
	int8 opcode = g_sc_attackobjpacket; 
	int8 type = 0x01; 
	int8 unk1 = 0x09; 
 
	int8 heading = chm.getHeading(cp); 
 
	unsigned char unk2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xB9, 0x61, 0x1E, 0x01, 0x02, 0x08, 0x00 }; 
 
	memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&type,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&myobj,4); // need my obj 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&targetid,4); 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&unk1,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&heading,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&unk2,12); 
 
	sendpacket( bufatk, 24, ptr ); 
	chm.checkAttacknotify(cp,ptr,targetid); 
	//sendAttackToAll(ptr, cp, myobj, targetid); 
} 
 
void GS_Attack::sendAttackToAll(DWORD ptr, unsigned int atkcp, unsigned long attackerid, unsigned long targetid) 
{ 
	char bufatk[24]; 
	char* buf_ptr = bufatk; 
	int8 opcode = g_sc_attackobjpacket; 
	int8 type = 0x01; 
	int8 unk1 = 0x09; 
 
	int8 heading = chm.getHeading(atkcp); 
 
	unsigned char unk2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0xB9, 0x61, 0x1E, 0x01, 0x02, 0x08, 0x00 }; 
 
	memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&type,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&targetid,4); 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&attackerid,4); // need my obj 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&unk1,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&heading,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&unk2,12); 
 
	sendpacket( bufatk, 24, ptr ); 
}