www.pudn.com > loseserver.rar > ObjectsMultimap.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 "ObjectsMultimap.h" 
#include "CharMap.h" 
#include "Types.h" 
#include "GameServer.h" 
#include "Logging.h" 
 
#include "OpCodes.h" 
 
using namespace std; 
 
extern GameServer gs; 
extern charmap chm; 
 
int objects::sendmovepacket(DWORD ptr, unsigned long objid, unsigned int cp) 
{ 
	int16 locx = chm.getLocx(cp); 
	int16 locy = chm.getLocy(cp); 
	int8 heading = chm.getHeading(cp); 
 
	char buf[16]; 
	char* buf_ptr = buf; 
 
	unsigned char enddata[] = { 
	0x81, 0x00, 0x00, 0x00, 0x00, 0x00 
	}; 
 
	int8 opcode = g_sc_sendmovecharacter; 
 
    memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
 
	memcpy(buf_ptr, (char*)&objid, 4); 
	buf_ptr+=4; 
 
	memcpy(buf_ptr, (char*)&locx, 2); 
	buf_ptr+=2; 
 
	memcpy(buf_ptr, (char*)&locy, 2); 
	buf_ptr+=2; 
 
	memcpy(buf_ptr, (char*)&heading, 1); 
	buf_ptr+=1; 
 
	memcpy(buf_ptr, (char*)&enddata, 6); 
 
	sendpacket(buf, 16, ptr); 
	return 0; 
} 
 
int objects::senduserobjnewpack(DWORD ptr, unsigned long objid, unsigned int cp) 
{ 
	int8 opcode = g_sc_sendknownobject; 
	int8 addbyte = 0x00; 
	int8 addbyte1 = 0x01; // speed, 0= normal (?), 1 = fast, 2 = slow, 3 = ? 
 
	int8 setting = 0x04; // 0x04 = normal, 0x05 = poison. 
	unsigned long iconid = 0x00000000; // no icon 
 
	char buf[60]; 
	char* buf_ptr = buf; // done so we can mover buf_ptr to were we need to memcpy 
 
	unsigned char unknown0[] = { 0x3D, 0x00 }; 
	unsigned char unknown1[] = { 0x00, 0x00, 0x00, 0x00 }; // exp 
	unsigned char unknown2[] = { 0x00, 0x00 }; 
	unsigned char unknown3[] = { 
	0x00, 0x00, 0xFF, 0x00, 0x00, 0x80, 0x0D // unknown 
	}; 
 
	memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
 
	int16 locx = chm.getLocx(cp); 
	memcpy(buf_ptr, (char*)&locx, 2); 
	buf_ptr+=2; 
 
	int16 locy = chm.getLocy(cp); 
	memcpy(buf_ptr, (char*)&locy, 2); 
	buf_ptr+=2; 
 
	memcpy(buf_ptr,(char*)&objid, 4);  
	buf_ptr+=4; 
 
	// char class based on list.spr ? 
	int16 chargfxid = chm.getClassid(cp); 
	memcpy(buf_ptr, (char*)&chargfxid, 2); 
	buf_ptr+=2; 
 
	int8 status = chm.getStatus(cp); 
	memcpy(buf_ptr, (char*)&status, 1); 
	buf_ptr+=1; 
 
	// dunno these but all 0x00 
	//memcpy(buf_ptr, (char*)&addbyte, 1); // makes char invis (0x01), cannot move. 
	memcpy(buf_ptr, (char*)&setting, 1); // makes char invis (0x01), cannot move. 
	buf_ptr+=1; 
	memcpy(buf_ptr, (char*)&addbyte, 1); // dunno (0x01 = running) 
	buf_ptr+=1; 
	memcpy(buf_ptr, (char*)&addbyte1, 1); // speed 
	buf_ptr+=1; 
	memcpy(buf_ptr, (char*)&unknown1, 4); // exp points 
	buf_ptr+=4; 
 
	int16 lawful = chm.getLawful(cp); 
	memcpy(buf_ptr, (char*)&lawful, 2); 
	buf_ptr+=2; 
 
	string us = chm.getCharname(cp); 
	char * name = strdup(us.c_str()); 
	memcpy(buf_ptr,(char*)name, strlen(name)); 
	buf_ptr+=strlen(name); 
 
	memcpy(buf_ptr, (char*)&addbyte, 1); 
	buf_ptr+=1; 
	//---- 
	string ustitle = chm.getTitle(cp); 
	char * title = strdup(ustitle.c_str());	 
	memcpy(buf_ptr,(char*)title, strlen(title)); 
	buf_ptr+=strlen(title); 
 
	memcpy(buf_ptr, (char*)&addbyte, 1); 
	buf_ptr+=1; 
	 
	memcpy(buf_ptr, (char*)&setting, 1); 
	buf_ptr+=1; 
	memcpy(buf_ptr, (char*)&iconid, 4); 
	buf_ptr+=4; 
	//---- 
	string clanus = chm.getClanname(cp); 
	char * clanname = strdup(clanus.c_str()); 
	memcpy(buf_ptr,(char*)clanname, strlen(clanname)); 
	buf_ptr+=strlen(clanname); 
 
	memcpy(buf_ptr, (char*)&addbyte, 1); 
	buf_ptr+=1; 
 
	memcpy(buf_ptr, (char*)&unknown3, 7); 
 
	int size = strlen(name)+strlen(clanname)+strlen(title)+36; 
	sendpacket(buf, size, ptr); 
	return 0; 
} 
 
void objects::sendnewheading(DWORD ptr, unsigned int cp, unsigned long objid) 
{ 
	int8 opcode = g_sc_sendheading; 
	unsigned char data[] = { 0x00, 0x36 }; 
	// sends packets to all that knows you that you are changing heading. 
	char buf[8]; 
	char* buf_ptr = buf; 
 
	int8 heading = chm.getHeading(cp); 
 
	memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&objid,4); 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&heading,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&data,2); 
 
	sendpacket( buf, 8, ptr ); 
} 
 
void objects::deleteuserpack(unsigned int cp, DWORD ptr, unsigned long ObjectId) 
{ 
	int8 opcode = g_sc_deleteuserobject; 
	unsigned char data[] = { 0x02, 0x00, 0xDF }; 
	// sends packets to all that knows you that you log out. 
	char buf[8]; 
	char* buf_ptr = buf; 
 
	memcpy(buf_ptr,(char*)&opcode,1); 
	buf_ptr+=1; 
	memcpy(buf_ptr,(char*)&ObjectId,4); 
	buf_ptr+=4; 
	memcpy(buf_ptr,(char*)&data,3); 
 
	sendpacket( buf, 8, ptr ); 
}