www.pudn.com > loseserver.rar > WorldKnown.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 "WorldKnown.h" 
#include "WorldNPC.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; 
extern worldnpc npc; 
 
void WorldKnown::sendnewknown(DWORD ptr, unsigned long obj) 
{ 
	npc.sendnpcobject(ptr, obj); 
} 
 
void WorldKnown::deleteobjpack(DWORD ptr, unsigned int cp, unsigned long obj) 
{ 
	chm.removeuserobj(cp, ptr, obj); 
} 
 
// send door change packet to all users 
void WorldKnown::changedoorstatus(char * data) 
{ 
	int16 locx = *((int16*)&data[0]); 
	int16 locy = *((int16*)&data[sizeof(locx)]); 
	unsigned long objid = *((unsigned long*)&data[sizeof(locx)+sizeof(locy)]); 
 
	bool doorclosed; 
 
	int8 doorstatus; 
	doorstatus = npc.getStatus(objid); 
 
	if(doorstatus == door_closed) 
	{ 
		doorclosed = true; 
		npc.setStatus(objid, door_open); 
	} 
	else if(doorstatus == door_open) 
	{ 
		doorclosed = false; 
		npc.setStatus(objid, door_closed); 
	} 
 
	for (multimap::iterator it = wo.begin(); it != wo.end(); ++it) 
	{ 
		unsigned long id = (*it).first; 
		unsigned int thiscp = (*it).second.cp; 
		DWORD thisptr = (*it).second.ptr; 
 
		if (objid == id) 
		{ 
			int8 opcode = g_sc_changeddoorstatus; 
			unsigned char blah[] = { 0x00, 0x06 }; 
 
			char buf[8]; 
			char* buf_ptr = buf; 
 
			memcpy(buf_ptr,(char*)&opcode,1); 
			buf_ptr+=1; 
			memcpy(buf_ptr,(char*)&objid,4); // need my obj 
			buf_ptr+=4; 
			// door status 
			if(doorclosed == true) 
			{ 
				int8 doorint8 = door_open; 
				memcpy(buf_ptr,(char*)&doorint8,1); 
				buf_ptr+=1;				 
			} 
			else if(doorclosed == false) 
			{ 
				int8 doorint8 = door_closed; 
				memcpy(buf_ptr,(char*)&doorint8,1); 
				buf_ptr+=1;				 
			} 
			memcpy(buf_ptr,(char*)blah, 2); 
			sendpacket( buf, 8, thisptr ); 
 
			// next packet to send. 
			int8 opcode1 = g_sc_changeattribute; 
			int8 unk1 = 0x01; 
			int16 unk2 = 0x001E; 
 
			char buf1[8]; 
			char* buf_ptr1 = buf1; 
			memcpy(buf_ptr1,(char*)&opcode1, 1); 
			buf_ptr1+=1; 
 
			memcpy(buf_ptr1,(char*)&locx, 2); 
			buf_ptr1+=2; 
			memcpy(buf_ptr1,(char*)&locy, 2); 
			buf_ptr1+=2; 
			memcpy(buf_ptr1,(char*)&unk1, 1); 
			buf_ptr1+=1; 
			memcpy(buf_ptr1,(char*)&unk2, 2); 
 
			sendpacket( buf1, 8, thisptr ); 
		} 
	} 
}