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


/* 
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 "Types.h" 
#include "Logging.h" 
 
using namespace std; 
 
// pointer to send packet from main file 
void sendpacket(char * data, int size, DWORD ptr); 
 
struct characters 
{ 
  unsigned int socket; 
  DWORD ptr; 
 
  // characters stats 
  string charname; 
  int16 hp; 
  int16 maxhp; 
  int16 mp; 
  int16 maxmp; 
  int8 str; 
  int8 dex; 
  int8 con; 
  int8 cha; 
  int8 wis; 
  int8 intel; 
  int16 lawful; 
  int8 level; 
 
  // clan relatet 
  string clanname; 
  string title; 
 
  // other inportant info 
  int8 ac; 
  int8 nutrition; 
  int8 weight; 
  int8 fireress; 
  int8 windress; 
  int8 waterress; 
  int8 earthress; 
 
  // characters location 
  int16 locx; 
  int16 locy; 
  int8 heading; 
  int16 mapid; 
  
  // character general info 
  int8 gender; 
  unsigned long objectid; 
  unsigned long exp; 
  int charclass; 
  int isgm; 
 
  // stuff for npc, doors ect. 
  int8 status; // running, moving, open, closed, ect. 
  string classtype; // type : user, npc, door, monster. 
}; 
 
class charmap 
{ 
private: 
    map chmap; 
	map::iterator scansearch; 
	struct characters ch; 
	int Sendtimenow(DWORD ptr); 
	int checkknown(DWORD myptr, DWORD ptr, unsigned int key, unsigned int cp, unsigned long OtherObj, unsigned long MyObj); 
	int sendatkpack(DWORD ptr, unsigned int cp, unsigned long oobj, unsigned long myobj); 
	void sendskillpack(DWORD ptr, unsigned int cp, unsigned long oobj, unsigned long myobj, int8 type, int16 typez); 
 
public: 
	void removeuserobj(unsigned int cp, DWORD ptr, unsigned long ObjectId); 
 
	//************************ 
	// std::map remove a map 
	//************************ 
	void removeMap(int keyid) 
	{ 
		chmap.erase(keyid); 
	} 
	//************************ 
	// std::map setters / getters 
	//************************ 
	//** Socket ** 
    void setSocket(int key, unsigned int socket) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.socket = socket; 
		else 
		{			  
			ch.socket = socket; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Socket ** 
	unsigned int getSocket(int key) 
    { 
        unsigned int socket = chmap[key].socket; 
        return socket; 
    } 
	//** Users network PTR ** 
    void setPtr(int key, DWORD ptr) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.ptr = ptr; 
		else 
		{			  
			ch.ptr = ptr; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Users network PTR ** 
	DWORD getPtr(int key) 
    { 
        DWORD ptr = chmap[key].ptr; 
        return ptr; 
    } 
 
    //** Charname ** 
	void setCharname(int key, string charname) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.charname = charname; 
		else 
		{			  
			ch.charname = charname; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Charname ** 
	string getCharname(int key) 
	{ 
		string charname = chmap[key].charname; 
		return charname; 
	} 
    //** Clan name ** 
	void setClanname(int key, string clanname) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.clanname = clanname; 
		else 
		{			  
			ch.clanname = clanname; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Clan name ** 
	string getClanname(int key) 
	{ 
		string clanname = chmap[key].clanname; 
		return clanname; 
	} 
    //** Title ** 
	void setTitle(int key, string title) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.title = title; 
		else 
		{ 
			ch.title = title; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Title ** 
	string getTitle(int key) 
	{ 
		string title = chmap[key].title; 
		return title; 
	} 
    //** Type ( user, npc, door, monster ) ** 
	void setClasstype(int key, string classtype) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.classtype = classtype; 
		else 
		{			  
			ch.classtype = classtype; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Charname ** 
	string getClasstype(int key) 
	{ 
		string classtype = chmap[key].classtype; 
		return classtype; 
	} 
    //** Is character a GM ** 
	void setIsgm(int key, int isgm) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.isgm = isgm; 
		else 
		{ 
			ch.isgm = isgm; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Is character a GM ** 
	int getIsgm(int key) 
	{ 
		int isgm = chmap[key].isgm; 
		return isgm; 
	} 
	//** Loc X ** 
    void setLocx(int key, int16 locx) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.locx = locx; 
		else 
		{			  
			ch.locx = locx; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Loc X ** 
	int16 getLocx(int key) 
	{ 
		int16 locx = chmap[key].locx; 
		return locx; 
	} 
	//** Loc Y ** 
    void setLocy(int key, int16 locy) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.locy = locy; 
		else 
		{			  
			ch.locy = locy; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Loc Y ** 
	int16 getLocy(int key) 
	{ 
		int16 locy = chmap[key].locy; 
		return locy; 
	} 
	//** Hp ** 
    void setHp(int key, int16 hp) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.hp = hp; 
		else 
		{			  
			ch.hp = hp; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Hp ** 
	int16 getHp(int key) 
	{ 
		int16 hp = chmap[key].hp; 
		return hp; 
	} 
	//** Max Hp ** 
	void setMaxhp(int key, int16 maxhp) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.maxhp = maxhp; 
		else 
		{			  
			ch.maxhp = maxhp; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Max Hp ** 
	int16 getMaxhp(int key) 
	{ 
		int16 maxhp = chmap[key].maxhp; 
		return maxhp; 
	} 
	//** Mp ** 
    void setMp(int key, int16 mp) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.mp = mp; 
		else 
		{			  
			ch.mp = mp; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Mp ** 
	int16 getMp(int key) 
	{ 
		int16 mp = chmap[key].mp; 
		return mp; 
	} 
	//** Max Mp ** 
    void setMaxmp(int key, int16 maxmp) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.maxmp = maxmp; 
		else 
		{ 
			  
			ch.maxmp = maxmp; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Max Mp ** 
	int16 getMaxmp(int key) 
	{ 
		int16 maxmp = chmap[key].maxmp; 
		return maxmp; 
	} 
	//** Armor Class ** 
    void setAc(int key, int8 ac) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.ac = ac; 
		else 
		{ 
			ch.ac = ac; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Armor Class ** 
	int8 getAc(int key) 
	{ 
		int8 ac = chmap[key].ac; 
		return ac; 
	} 
	//** Status ** 
    void setStatus(int key, int8 status) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.status = status; 
		else 
		{			  
			ch.status = status; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Status ** 
	int8 getStatus(int key) 
	{ 
		int8 status = chmap[key].status; 
		return status; 
	} 
	//** Strenght ** 
    void setStr(int key, int8 str) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.str = str; 
		else 
		{			  
			ch.str = str; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Strenght ** 
	int8 getStr(int key) 
	{ 
		int8 str = chmap[key].str; 
		return str; 
	} 
	//** Dexterity ** 
    void setDex(int key, int8 dex) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.dex = dex; 
		else 
		{			  
			ch.dex = dex; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Dexterity ** 
	int8 getDex(int key) 
	{ 
		int8 dex = chmap[key].dex; 
		return dex; 
	}	 
	//** Constitution ** 
    void setCon(int key, int8 con) 
    {		 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.con = con; 
		else 
		{			  
			ch.con = con; 
			chmap.insert(make_pair(key, ch)); 
		} 
 
    } 
	//** Constitution ** 
	int8 getCon(int key) 
	{ 
		int8 con = chmap[key].con; 
		return con; 
	} 
	//** Charisma ** 
    void setCha(int key, int8 cha) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.cha = cha; 
		else 
		{ 
			  
			ch.cha = cha; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Charisma ** 
	int8 getCha(int key) 
	{ 
		int8 cha = chmap[key].cha; 
		return cha; 
	} 
	//** Wisdom ** 
    void setWis(int key, int8 wis) 
    { 
		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.wis = wis; 
		else 
		{			  
			ch.wis = wis; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Wisdom ** 
	int8 getWis(int key) 
	{ 
		int8 wis = chmap[key].wis; 
		return wis; 
	} 
	//** Intelligence ** 
    void setIntel(int key, int8 intel) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.intel = intel; 
		else 
		{ 
			  
			ch.intel = intel; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Intelligence ** 
	int8 getIntel(int key) 
	{ 
		int8 intel = chmap[key].intel; 
		return intel; 
	} 
	//** lawful ** 
    void setLawful(int key, int16 lawful) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.lawful = lawful; 
		else 
		{			  
			ch.lawful = lawful; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** lawful ** 
	int16 getLawful(int key) 
	{ 
		int16 lawful = chmap[key].lawful; 
		return lawful; 
	} 
	//** level ** 
    void setLevel(int key, int8 level) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.level = level; 
		else 
		{			  
			ch.level = level; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** level ** 
	int8 getLevel(int key) 
	{ 
		int8 level = chmap[key].level; 
		return level; 
	} 
	//** Nutrition (food) ** 
    void setNutrition(int key, int8 nutrition) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.nutrition = nutrition; 
		else 
		{			  
			ch.nutrition = nutrition; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Nutrition (food) ** 
	int8 getNutrition(int key) 
	{ 
		int8 nutrition = chmap[key].nutrition; 
		return nutrition; 
	} 
	//** Weight ** 
    void setWeight(int key, int8 weight) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.weight = weight; 
		else 
		{			  
			ch.weight = weight; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Weight ** 
	int8 getWeight(int key) 
	{ 
		int8 weight = chmap[key].weight; 
		return weight; 
	} 
	//** Fire Resistance ** 
    void setFireress(int key, int8 fireress) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.fireress = fireress; 
		else 
		{			  
			ch.fireress = fireress; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Fire Resistance ** 
	int8 getFireress(int key) 
	{ 
		int8 fireress = chmap[key].fireress; 
		return fireress; 
	} 
	//** Wind Resistance ** 
    void setWindress(int key, int8 windress) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.windress = windress; 
		else 
		{			  
			ch.windress = windress; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	int8 getWindress(int key) 
	{ 
		int8 windress = chmap[key].windress; 
		return windress; 
	} 
	//** Water Resistance ** 
    void setWaterress(int key, int8 waterress) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.waterress = waterress; 
		else 
		{			  
			ch.waterress = waterress; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Water Resistance ** 
	int8 getWaterress(int key) 
	{ 
		int8 waterress = chmap[key].waterress; 
		return waterress; 
	} 
	//** Earth Resistance ** 
    void setEarthress(int key, int8 earthress) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.earthress = earthress; 
		else 
		{			  
			ch.earthress = earthress; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Earth Resistance ** 
	int8 getEarthress(int key) 
	{ 
		int8 earthress = chmap[key].earthress; 
		return earthress; 
	} 
	//** Heading ** 
    void setHeading(int key, int8 heading) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.heading = heading; 
		else 
		{			  
			ch.heading = heading; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Heading ** 
	int8 getHeading(int key) 
	{ 
		int8 heading = chmap[key].heading; 
		return heading; 
	} 
	//** Map ID ** 
    void setMapid(int key, int16 mapid) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.mapid = mapid; 
		else 
		{			  
			ch.mapid = mapid; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Map ID ** 
	int16 getMapid(int key) 
	{ 
		int16 mapid = chmap[key].mapid; 
		return mapid; 
	} 
	//** Object ID ** 
    void setObjectid(int key, unsigned long objectid) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.objectid = objectid; 
		else 
		{			  
			ch.objectid = objectid; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Object ID ** 
	unsigned long getObjectid(int key) 
	{ 
		unsigned long objectid = chmap[key].objectid; 
		return objectid; 
	} 
	//** Character Class ID (from list.spr) ** 
    void setClassid(int key, int charclass) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.charclass = charclass; 
		else 
		{			  
			ch.charclass = charclass; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Character Class ID (from list.spr) ** 
	int getClassid(int key) 
	{ 
		int charclass = chmap[key].charclass; 
		return charclass; 
	} 
	//** Experience ** 
    void setExp(int key, unsigned long exp) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.exp = exp; 
		else 
		{			  
			ch.exp = exp; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Experience ** 
	unsigned long getExp(int key) 
	{ 
		unsigned long exp = chmap[key].exp; 
		return exp; 
	} 
	//** Gender ** 
    void setGender(int key, int8 gender) 
    { 
 		map::iterator it = chmap.find(key); 
		if(it != chmap.end()) 
			it->second.gender = gender; 
		else 
		{			  
			ch.gender = gender; 
			chmap.insert(make_pair(key, ch)); 
		} 
    } 
	//** Gender ** 
	int8 getGender(int key) 
	{ 
		int8 gender = chmap[key].gender; 
		return gender; 
	} 
 
	//**************************// 
	//*   Utilities for map.   *// 
	//**************************// 
 
	//** find a username (whisper & /who) ** 
 	DWORD findUser(int key, string username) 
	{ 
		map::iterator scanb; 
		for(scanb = chmap.begin() ; scanb != chmap.end() ; scanb++ ) 
		{ 
			unsigned int port = chmap[scanb->first].socket; 
			string rec = chmap[port].charname; 
			char * chname = strdup(rec.c_str()); 
			DWORD userptr = chmap[port].ptr; 
 
			if(username != rec) 
			{ 
				// do nada, wasnt the one we where looking for 
			} 
			else 
			{ 
				// found a user 
				return userptr; 
				break; 
			} 
		} 
		return 0; 
	} 
	//** get total amount of users online ** 
	int amountOnline() 
	{ 
		int amount = 0; 
		 
		map::iterator scana; 
		for(scana = chmap.begin() ; scana != chmap.end() ; scana++ ) 
		{ 
			amount++; 
		} 
		return amount; 
		amount = 0; 
	} 
	// ** send chat to all ** 
	int sendtoall(char * chatstring, unsigned int cp, int8 myopcode, int8 mytype) 
	{ 
		if(chmap.empty() == true) 
		{ 
			// empty, no reason to do anything. 
			return 0; 
		} 
		else 
		{ 
			unsigned long userobjx = getObjectid(cp); 
			int16 mylocx = getLocx(cp); 
			int16 mylocy = getLocy(cp); 
			int16 mymapid = getMapid(cp); 
 
			int8 opcode = myopcode; 
			int8 type = mytype; 
 
			map::iterator scanc; 
			for(scanc = chmap.begin() ; scanc != chmap.end() ; scanc++ ) 
			{ 
				unsigned int port = chmap[scanc->first].socket; 
				DWORD userptr = chmap[port].ptr; 
 
				string us = getCharname(cp); 
				char * charname = strdup(us.c_str()); 
 
				if(opcode == 0x5F && type == 0x00) 
				{ 
					int16 olocx = chmap[port].locx; 
					int16 olocy = chmap[port].locy; 
					int16 omapid = chmap[port].mapid; 
 
					int16 xmax = mylocx + 10; 
					int16 xmin = mylocx - 10; 
					int16 ymax = mylocy + 10; 
					int16 ymin = mylocy - 10; 
 
					if( olocy >= ymax ) { 
						//skip user 
					} 
					else if( olocy <= ymin ) { 
						//skip user 
					} 
					else if( olocx >= xmax ) { 
						//skip user 
					} 
					else if( olocx <= xmin ) { 
						//skip user 
					} 
					else 
					{ 
						if(mymapid == omapid) 
						{ 
							// normal chat. 
							int8 endbyte = 0x00; 
							char * message = (char*)&chatstring[1]; 
							int size = strlen(message); 
		 
							char buffer[120]; 
							char* buf_ptr = buffer; 
		 
							memcpy(buf_ptr,(char*)&opcode,1); 
							buf_ptr+=1; 
							memcpy(buf_ptr,(char*)&type,1); 
							buf_ptr+=1; 
 
							memcpy(buf_ptr,(char*)&userobjx,4); 
							buf_ptr+=4; 
 
							char* name = new char[14]; 
							sprintf(name,"%s: ", charname); 
 
							memcpy(buf_ptr,(char*)name, strlen(name)); 
							buf_ptr+=strlen(name); 
							memcpy(buf_ptr,(char*)message, size); 
							buf_ptr+=size; 
			 
							memcpy(buf_ptr,(char*)&endbyte,1); 
		 
							int fullsize = strlen(message)+strlen(charname)+9; 
		 
							sendpacket( buffer, fullsize, userptr ); 
						} 
					} 
				} 
				else if(opcode == 0x5F && type == 0x02) 
				{ 
					int16 olocx = chmap[port].locx; 
					int16 olocy = chmap[port].locy; 
					int16 omapid = chmap[port].mapid; 
					 
					int16 xmax = mylocx + 50; 
					int16 xmin = mylocx - 50; 
					int16 ymax = mylocy + 50; 
					int16 ymin = mylocy - 50; 
 
					if( olocy >= ymax ) { 
						//skip user 
					} 
					else if( olocy <= ymin ) { 
						//skip user 
					} 
					else if( olocx >= xmax ) { 
						//skip user 
					} 
					else if( olocx <= xmin ) { 
						//skip user 
					} 
					else 
					{ 
						if(mymapid == omapid) 
						{ 
							// shout. 
							int8 opcode = myopcode; 
							int8 type = 0x02; 
							int8 endbyte = 0x00; 
							char * message = (char*)&chatstring[1]; 
							int size = strlen(message); 
 
							char buffer[120]; 
							char* buf_ptr = buffer; 
 
							memcpy(buf_ptr,(char*)&opcode,1); 
							buf_ptr+=1; 
							memcpy(buf_ptr,(char*)&type,1); 
							buf_ptr+=1; 
 
							memcpy(buf_ptr,(char*)&userobjx,4); 
							buf_ptr+=4; 
 
							char* name = new char[14]; 
							sprintf(name,"<%s> ", charname); 
 
							memcpy(buf_ptr,(char*)name, strlen(name)); 
							buf_ptr+=strlen(name); 
							memcpy(buf_ptr,(char*)message, size); 
							buf_ptr+=size; 
			 
							memcpy(buf_ptr,(char*)&endbyte,1); 
							buf_ptr+=1; 
 
							memcpy(buf_ptr,(char*)&mylocx,2); 
							buf_ptr+=2; 
							memcpy(buf_ptr,(char*)&mylocy,2); 
 
							int fullsize = strlen(message)+strlen(charname)+14; 
 
							sendpacket( buffer, fullsize, userptr ); 
						} 
					} 
				} 
				else if(opcode == 0x46 && type == 0x03) 
				{ 
					// global chatting. 
					char buf[120]; 
					char* buf_ptr = buf; 
 
					int8 opcode = myopcode; 
					char * message = (char*)&chatstring[1]; 
					int size = strlen(message); 
 
					int8 type = mytype; 
					memcpy(buf_ptr,(char*)&opcode,1); 
					buf_ptr+=1; 
					memcpy(buf_ptr,(char*)&type,1); 
					buf_ptr+=1; 
 
					char * charactername; 
					if(getIsgm(cp) == 0) 
					{ 
						charactername = charname; 
					} 
					else 
					{ 
						charactername = "******"; 
					} 
 
					char* name = new char[14]; 
					sprintf(name,"[%s] ", charactername); 
 
					memcpy(buf_ptr,(char*)name, strlen(name)); 
					buf_ptr+=strlen(name); 
					memcpy(buf_ptr,(char*)message, size); 
					buf_ptr+=size; 
					int8 endbyte = 0x00; 
					memcpy(buf_ptr,(char*)&endbyte,1); 
 
					int fullsize = strlen(message)+strlen(charactername)+6; 
 
					sendpacket( buf, fullsize, userptr ); 
				} 
			} 
		} 
		return 0; 
	} 
	//** send time to all 
	int sendTime() 
	{		 
		map::iterator scanx; 
		for(scanx = chmap.begin() ; scanx != chmap.end() ; scanx++ ) 
		{ 
			unsigned int port = chmap[scanx->first].socket; 
			DWORD userptr = chmap[port].ptr; 
			Sendtimenow(userptr); 
		} 
		return 0; 
	} 
 
	//** check user locations 
	int checkUserLocataion(unsigned int cp, DWORD ptr) 
	{ 
		int16 mylocx = getLocx(cp); 
		int16 mylocy = getLocy(cp); 
		int16 mymapid = getMapid(cp); 
		 
		// set max x,y away before notifying 
		int16 xmax = mylocx + 15; 
		int16 xmin = mylocx - 15; 
		int16 ymax = mylocy + 15; 
		int16 ymin = mylocy - 15; 
 
		unsigned long ourobj = getObjectid(cp); 
		unsigned int thisuser = getSocket(cp); 
		unsigned long otherobj; 
		int16 olocx; 
		int16 olocy; 
		DWORD optr; 
 
		map::iterator itloc; 
		for(itloc = chmap.begin() ; itloc != chmap.end() ; itloc++ ) 
		{ 
			unsigned int otheruser = chmap[itloc->first].socket; 
			olocx = getLocx(otheruser); 
			olocy = getLocy(otheruser); 
			optr = getPtr(otheruser); 
			otherobj = getObjectid(otheruser); 
 
			if( olocy >= ymax ) { 
				//skip user 
				removeuserobj(cp, ptr, otherobj); 
				removeuserobj(otheruser, optr, ourobj); 
			} 
			else if( olocy <= ymin ) { 
				//skip user 
				removeuserobj(cp, ptr, otherobj); 
				removeuserobj(otheruser, optr, ourobj); 
			} 
			else if( olocx >= xmax ) { 
				//skip user 
				removeuserobj(cp, ptr, otherobj); 
				removeuserobj(otheruser, optr, ourobj); 
			} 
			else if( olocx <= xmin ) { 
				//skip user 
				removeuserobj(cp, ptr, otherobj); 
				removeuserobj(otheruser, optr, ourobj); 
			} 
			else 
			{ 
				int16 omapid = chmap[otheruser].mapid; 
				//check if you are on same map. 
				if(mymapid == omapid) 
				{ 
					// check if this is yourself or other player 
					if(otheruser < thisuser || otheruser > thisuser) 
					{ 
						//add this user to known objects. 
						otherobj = getObjectid(otheruser); 
						checkknown(ptr, optr, cp, otheruser, otherobj, ourobj); 
					} 
				}			 
			} 
		} 
		return 0; 
	} 
 
	int checkAttacknotify(unsigned int cp, DWORD ptr, unsigned long targetid) 
	{ 
		int16 mylocx = getLocx(cp); 
		int16 mylocy = getLocy(cp); 
		int16 mymapid = getMapid(cp); 
		 
		// set max x,y away before notifying 
		int16 xmax = mylocx + 15; 
		int16 xmin = mylocx - 15; 
		int16 ymax = mylocy + 15; 
		int16 ymin = mylocy - 15; 
 
		unsigned long ourobj = getObjectid(cp); 
		unsigned int thisuser = getSocket(cp); 
		unsigned long otherobj; 
		int16 olocx; 
		int16 olocy; 
		DWORD optr; 
 
		map::iterator itloc; 
		for(itloc = chmap.begin() ; itloc != chmap.end() ; itloc++ ) 
		{ 
			unsigned int otheruser = chmap[itloc->first].socket; 
			olocx = getLocx(otheruser); 
			olocy = getLocy(otheruser); 
			optr = getPtr(otheruser); 
			otherobj = getObjectid(otheruser); 
 
			if( olocy >= ymax ) { 
				//skip user 
			} 
			else if( olocy <= ymin ) { 
				//skip user 
			} 
			else if( olocx >= xmax ) { 
				//skip user 
			} 
			else if( olocx <= xmin ) { 
				//skip user 
			} 
			else 
			{ 
				int16 omapid = chmap[otheruser].mapid; 
				//check if you are on same map. 
				if(mymapid == omapid) 
				{ 
					// check if this is yourself or other player 
					if(otheruser < thisuser || otheruser > thisuser) 
					{ 
						//add this user to known objects. 
						otherobj = getObjectid(otheruser); 
						sendatkpack( optr, cp, ourobj, targetid ); 
					} 
				}			 
			} 
		} 
		return 0; 
	} 
 
	int SendToViewSkill(unsigned int cp, DWORD ptr, unsigned long myobj, unsigned long tobj, int8 type, int16 typez) 
	{ 
		int16 mylocx = getLocx(cp); 
		int16 mylocy = getLocy(cp); 
		int16 mymapid = getMapid(cp); 
		 
		// set max x,y away before notifying 
		int16 xmax = mylocx + 15; 
		int16 xmin = mylocx - 15; 
		int16 ymax = mylocy + 15; 
		int16 ymin = mylocy - 15; 
 
		unsigned long ourobj = getObjectid(cp); 
		unsigned int thisuser = getSocket(cp); 
		unsigned long otherobj; 
		int16 olocx; 
		int16 olocy; 
		DWORD optr; 
 
		map::iterator itloc; 
		for(itloc = chmap.begin() ; itloc != chmap.end() ; itloc++ ) 
		{ 
			unsigned int otheruser = chmap[itloc->first].socket; 
			olocx = getLocx(otheruser); 
			olocy = getLocy(otheruser); 
			optr = getPtr(otheruser); 
			otherobj = getObjectid(otheruser); 
 
			if( olocy >= ymax ) { 
				//skip user 
			} 
			else if( olocy <= ymin ) { 
				//skip user 
			} 
			else if( olocx >= xmax ) { 
				//skip user 
			} 
			else if( olocx <= xmin ) { 
				//skip user 
			} 
			else 
			{ 
				int16 omapid = chmap[otheruser].mapid; 
				//check if you are on same map. 
				if(mymapid == omapid) 
				{ 
					if(otheruser < thisuser || otheruser > thisuser) 
					{ 
						sendskillpack( optr, cp, myobj, tobj, type, typez); 
					} 
				}			 
			} 
		} 
		return 0; 
	} 
};