📄 client.cpp
字号:
#include "../Common.h"
#include "../IDList.h"
#include "../NetCode/OpCodes.h"
#include "Client.h"
#include "Character.h"
Client::Client(wxSocketBase *CSocket) {
CurrentSocket = CSocket;
CurrentChar = 0; Admin = 0;
}
Client::~Client (void) {
CharHashMap::iterator it;
for (it = Characters.begin(); it != Characters.end(); ++it)
if (it->second) delete it->second;
}
void Client::CharacterEnum(wowPacket *packet) {
LOG(_T("[Client] CMSG_CHAR_ENUM: sending %d character(s)."), Characters.size());
wowPacket *Chars = new wowPacket(packet->GetSocket());
Chars->PutHeader(SMSG_CHAR_ENUM);
Chars->Putu8(Characters.size());
CharHashMap::iterator it;
for (it = Characters.begin(); it != Characters.end(); ++it) {
Character *c = it->second;
Chars->Putu32(c->GetGUID().GetLo()); Chars->Putu32(c->GetGUID().GetHi());
Chars->Putcstr0(c->GetName());
Chars->Putu8(c->GetRace()); Chars->Putu8(c->GetClass());
Chars->Putu8(c->GetSex()); Chars->Putu8(c->GetSkin());
Chars->Putu8(c->GetFace()); Chars->Putu8(c->GetHairStyle());
Chars->Putu8(c->GetHairColor()); Chars->Putu8(c->GetFacialHair());
Chars->Putu8(c->GetLevel());
Chars->Putu32(c->HomeCity); Chars->Putu32(c->Realm);
Chars->Putf32(c->Position.PosX); Chars->Putf32(c->Position.PosY);
Chars->Putf32(c->Position.PosZ);
/* Pet / Guild? */
Chars->Putu32(0); Chars->Putu32(0);
Chars->Putu32(0); Chars->Putu32(0);
int i = 0;
Chars->Putu32(WEAPON_LEETSTAFF);
Chars->Putu8(slotLeftHand); ++i;
Chars->Putu32(WEAPON_TRISTAFF);
Chars->Putu8(slotRightHand); ++i;
/* pack.Putu32(0x00002788);
pack.Putu8(0x04); ++i;
pack.Putu32(0x000008ae);
pack.Putu8(0x05); ++i;
pack.Putu32(0x000026c4);
pack.Putu8(0x06); ++i;
pack.Putu32(0x000026c9);
pack.Putu8(0x07); ++i;*/
Chars->Putu32(0x00000cf0);
Chars->Putu8(0x0A); ++i;
Chars->Putu32(0x00002247);
Chars->Putu8(0x0e); ++i;
for (; i < 20; ++i) {
Chars->Putu32(0);
Chars->Putu8(0);
}
}
Chars->Finalize();
WorldThread::GetThread()->PostPacket(Chars);
}
void Client::CreateChar(wowPacket *packet) {
LOG(_T("[Client] CMSG_CHAR_CREATE: creating character."));
wowPacket *CharCreated = new wowPacket(packet->GetSocket());
CharCreated->PutHeader(SMSG_CHAR_CREATE);
packet->SkipHeader();
wxString name; packet->Getcstr(name);
ObjectManager *objman = WorldThread::GetThread()->GetObjectManager();
if (objman->ReverseObj.find(name) != objman->ReverseObj.end()) {
CharCreated->Putu8(CREATE_NAMETAKEN);
CharCreated->Finalize();
WorldThread::GetThread()->PostPacket(CharCreated);
return;
}
Character *nchar = new Character(this, name);
nchar->SetRace(packet->Getu8()); nchar->SetClass(packet->Getu8());
nchar->SetSex(packet->Getu8()); nchar->SetSkin(packet->Getu8());
nchar->SetFace(packet->Getu8()); nchar->SetHairStyle(packet->Getu8());
nchar->SetHairColor(packet->Getu8()); nchar->SetFacialHair(packet->Getu8());
nchar->SetLevel(packet->Getu8()); nchar->SetLoDmg(6); nchar->SetHiDmg(9);
short mesh = 0x32;
if (nchar->GetRace() < 7)
mesh = 0x2F + (nchar->GetRace() * 2) + nchar->GetSex();
else if (nchar->GetRace() == 7)
mesh = 0x061B + nchar->GetSex();
else if (nchar->GetRace() == 8)
mesh = 0x05C6 + nchar->GetSex();
nchar->SetDisplayID(mesh);
nchar->SetPosition(-8897.7002f, -173.28f, 81.510002f);
//nchar->SetPosition(0.0f, 0.0f, 100.0f);
nchar->SetStrength(15); nchar->SetBaseStrength(15);
nchar->SetAgility(15); nchar->SetBaseAgility(15);
nchar->SetStamina(15); nchar->SetBaseStamina(15);
nchar->SetIntellect(15); nchar->SetBaseIntellect(15);
nchar->SetSpirit(15); nchar->SetBaseSpirit(15);
nchar->SetXP(0);
nchar->SetNextXP(1000);
nchar->SetLevel(1);
nchar->SetHealth(100); nchar->SetMaxHealth(100);
nchar->SetMana(100); nchar->SetMaxMana(100);
/* Find sane values for the below */
nchar->SetFactionTemp(5);
nchar->SetAttackTimeL(3000);
nchar->SetAttackTimeR(2000);
nchar->SetBoundingRadi(0.38299999f);
nchar->SetWeaponReach(1.5f);
unsigned char actionbuttons[480] = {
0xCB, 0x19, 0x00, 0x00, 0x49, 0x02, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0xFF, 0xFF, 0xFF, 0x04, 0xEE, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} ;
memcpy(nchar->ActionButtons, actionbuttons, sizeof(wxUint32) * NumActionButtons);
CharCreated->Putu8(CREATE_OK);
CharCreated->Finalize();
WorldThread::GetThread()->PostPacket(CharCreated);
}
void Client::DeleteChar (wowPacket *packet) {
packet->SkipHeader();
wxUint32 lo = packet->Getu32(); wxUint32 hi = packet->Getu32();
wxLongLong id = wxLongLong(hi, lo);
if (Characters.find(id) != Characters.end()) {
LOG(_T("[UserManager] CMSG_CHAR_DELETE: deleting character '%s'."), Characters[id]->Name.c_str());
delete Characters[id];
Characters.erase(id);
wowPacket *CharDeleted = new wowPacket(packet->GetSocket());
CharDeleted->PutHeader(SMSG_CHAR_DELETE);
CharDeleted->Putu8(40);
CharDeleted->Finalize();
WorldThread::GetThread()->PostPacket(CharDeleted);
}
}
void Client::PlayerLogin (wowPacket *packet) {
/* TODO: Dynamicize it! */
LOG(_T("[Character] CMSG_PLAYER_LOGIN: Setting char as current."));
packet->SkipHeader();
wxUint32 lo = packet->Getu32(); wxUint32 hi = packet->Getu32();
wxLongLong id = wxLongLong(hi, lo);
CurrentChar = Characters[id];
CurrentChar->EnterWorld();
}
/*long Client::Logout () {
if (!LogoutStatus)
return -1;
if (LogoutStatus == 1)
return 20000; // TEMP - config option or constant
LOG(_T("[Client] Sending SMSG_LOGOUT_COMPLETE."));
wowPacket *LogComplete = new wowPacket(socket);
LogComplete->PutHeader(SMSG_LOGOUT_COMPLETE);
// LogComplete->Putu32(CurrentChar->ID.GetLo());
// LogComplete->Putu32(CurrentChar->ID.GetHi());
LogComplete->Finalize();
WorldThread::GetThread()->PostPacket(LogComplete);
return -1;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -