www.pudn.com > loseserver.rar > Gameserver.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 "Gameserver.h" #include "resource.h" #include "Logging.h" #include "CConnection.h" #include "Types.h" #include "OpCodes.h" #include "Skill.h" #include "Database.h" #include "ComWindows.h" #include "LoginMap.h" #include "CharMap.h" #include "ObjectsMultimap.h" #include "WorldNPC.h" using namespace std; //******************************************* // class defines //******************************************* extern database logindb; extern ComWindows com; extern LoginMap dblmap; extern charmap chm; extern objects obj; extern worldnpc npc; //*********************************************************** // Send new server time to all clients (every 50 seconds). //*********************************************************** int GameServer::SendTime(DWORD ptr) { int cp = 0x01; long mytime; mytime = logindb.getservertime(); tm * ptm; ptm = gmtime ( &mytime ); char buftime[8]; char* buf_ptr = buftime; int8 opcode = g_sc_ingametime; unsigned char unknown[] = { 0x01, 0x08, 0x00 }; memcpy(buf_ptr,(char*)&opcode,1); buf_ptr+=1; memcpy(buf_ptr,(char*)&mytime,4); buf_ptr+=4; memcpy(buf_ptr,(char*)&unknown,3); sendpacket( buftime, 8, ptr ); return 0; } //*********************************************************** // Movement (character is moving) //*********************************************************** void GameServer::Moving(char * newloc, DWORD ptr) { CConnection* c = reinterpret_cast (ptr); char cip[15]; unsigned int cp = 0; c->PeerInfo (&cip[0], 15, &cp); string us = chm.getCharname(cp); char * charname = strdup(us.c_str()); int16 myx = *((int16*)&newloc[0]); int16 myy = *((int16*)&newloc[sizeof(myx)]); int8 heading = *((int8*)&newloc[sizeof(myx)+sizeof(myy)]); chm.setLocx(cp, myx); chm.setLocy(cp, myy); chm.setHeading(cp, heading); npc.scanlocation(ptr, cp); chm.checkUserLocataion(cp, ptr); return; } //*********************************************************** // Turning (character is turning around) //*********************************************************** void GameServer::newheading(char * newheading, DWORD ptr) { CConnection* c = reinterpret_cast (ptr); char cip[15]; unsigned int cp = 0; c->PeerInfo (&cip[0], 15, &cp); string us = chm.getCharname(cp); char * charname = strdup(us.c_str()); int16 mapx = chm.getLocx(cp); int16 mapy = chm.getLocy(cp); unsigned long myobj = chm.getObjectid(cp); int8 heading = *((int8*)&newheading[0]); chm.setLocx(cp, mapx); chm.setLocy(cp, mapy); chm.setHeading(cp, heading); //chm.checkUserLocataion(cp, ptr); obj.newheadingpacket(ptr, cp, myobj); return; } //*********************************************************** // Skill Effect. //*********************************************************** void GameServer::skilleffect(char * buffer, DWORD ptr, int size) { 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 tobj; int8 level = *(int8*)&buffer[0]; int8 id = *(int8*)&buffer[1]; int16 skillid = id + level*10; if(size > 4) tobj = *(unsigned long*)&buffer[2]; else tobj = myobj; int8 type = 0x13; int16 typez = SkillTable[skillid]; int8 opcode = g_sc_chareffect; unsigned char unknown[] = { 0x00, 0x00 }; char buftime[8]; char* buf_ptr = buftime; memcpy(buf_ptr,(char*)&opcode,1); buf_ptr+=1; memcpy(buf_ptr,(char*)&myobj,4); buf_ptr+=4; memcpy(buf_ptr,(char*)&type,1); buf_ptr+=1; memcpy(buf_ptr,(char*)&unknown,2); sendpacket( buftime, 8, ptr ); opcode = g_sc_skilleffect; unsigned char unknownz[] = { 0x00 }; char buftimez[8]; char* buf_ptrz = buftimez; memcpy(buf_ptrz,(char*)&opcode,1); buf_ptrz+=1; memcpy(buf_ptrz,(char*)&tobj,4); buf_ptrz+=4; memcpy(buf_ptrz,(char*)&typez,2); buf_ptrz+=2; memcpy(buf_ptrz,(char*)&unknownz,1); sendpacket( buftimez, 8, ptr ); chm.SendToViewSkill(cp, ptr, myobj, tobj, type, typez); }