fixed some crashes (with vc80)

This commit is contained in:
Necroalbert 2007-03-05 20:30:53 +00:00
parent 7aaac21eca
commit 10e6b70c4d
4 changed files with 161 additions and 161 deletions

View File

@ -30,7 +30,7 @@ class ByteBuffer
{ {
}; };
const static size_t DEFAULT_SIZE = 0x1000; const static size_t DEFAULT_SIZE = 0xFF;
ByteBuffer(): _rpos(0), _wpos(0) ByteBuffer(): _rpos(0), _wpos(0)
{ {

View File

@ -8,11 +8,11 @@
enum AuthCmd enum AuthCmd
{ {
AUTH_LOGON_CHALLENGE = 0x00, AUTH_LOGON_CHALLENGE = 0x00,
AUTH_LOGON_PROOF = 0x01, AUTH_LOGON_PROOF = 0x01,
REALM_LIST = 0x10, REALM_LIST = 0x10,
}; };
struct SRealmHeader struct SRealmHeader
@ -41,26 +41,26 @@ struct AuthHandler
void (RealmSocket::*handler)(void); void (RealmSocket::*handler)(void);
}; };
struct sAuthLogonChallenge_S struct sAuthLogonChallenge_S
{ {
uint8 cmd; uint8 cmd;
uint8 error; uint8 error;
uint8 unk2; uint8 unk2;
uint8 B[32]; uint8 B[32];
uint8 g_len; uint8 g_len;
uint8 g[1]; uint8 g[1];
uint8 N_len; uint8 N_len;
uint8 N[32]; uint8 N[32];
uint8 salt[32]; uint8 salt[32];
uint8 unk3[16]; uint8 unk3[16];
}; };
struct sAuthLogonProof_S struct sAuthLogonProof_S
{ {
uint8 cmd; uint8 cmd;
uint8 error; uint8 error;
uint8 M2[20]; uint8 M2[20];
uint32 unk2; uint32 unk2;
}; };
const AuthHandler table[]= const AuthHandler table[]=
@ -126,7 +126,7 @@ void RealmSocket::_HandleRealmList(void)
{ {
std::string realmAddr; std::string realmAddr;
ByteBuffer realmbuf; ByteBuffer realmbuf;
realmbuf.reserve(ibuf.GetLength()); realmbuf.resize(ibuf.GetLength());
ibuf.Read((char*)realmbuf.contents(), ibuf.GetLength()); ibuf.Read((char*)realmbuf.contents(), ibuf.GetLength());
uint32 unk; uint32 unk;

View File

@ -33,10 +33,10 @@ WorldSession::~WorldSession()
{ {
WorldPacket *packet; WorldPacket *packet;
// clear the queue // clear the queue
while(!pktQueue.empty()) while(!pktQueue.empty())
{ {
packet = pktQueue.next(); packet = pktQueue.next();
delete packet; delete packet;
} }
_OnLeaveWorld(); _OnLeaveWorld();
@ -102,8 +102,8 @@ void WorldSession::Update(void)
{ {
WorldPacket *packet = pktQueue.next(); WorldPacket *packet = pktQueue.next();
for (uint16 i = 0; table[i].handler != NULL; i++) for (uint16 i = 0; table[i].handler != NULL; i++)
{ {
if (table[i].opcode == packet->GetOpcode()) if (table[i].opcode == packet->GetOpcode())
{ {
try try
@ -145,11 +145,11 @@ void WorldSession::Update(void)
} }
OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const
{ {
static OpcodeHandler table[] = static OpcodeHandler table[] =
{ {
{ SMSG_AUTH_CHALLENGE, &WorldSession::_HandleAuthChallengeOpcode }, { SMSG_AUTH_CHALLENGE, &WorldSession::_HandleAuthChallengeOpcode },
{ SMSG_AUTH_RESPONSE, &WorldSession::_HandleAuthResponseOpcode }, { SMSG_AUTH_RESPONSE, &WorldSession::_HandleAuthResponseOpcode },
{SMSG_CHAR_ENUM, &WorldSession::_HandleCharEnumOpcode}, {SMSG_CHAR_ENUM, &WorldSession::_HandleCharEnumOpcode},
{SMSG_SET_PROFICIENCY, &WorldSession::_HandleSetProficiencyOpcode}, {SMSG_SET_PROFICIENCY, &WorldSession::_HandleSetProficiencyOpcode},
@ -158,91 +158,91 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const
{SMSG_NAME_QUERY_RESPONSE, &WorldSession::_HandleNameQueryResponseOpcode}, {SMSG_NAME_QUERY_RESPONSE, &WorldSession::_HandleNameQueryResponseOpcode},
{SMSG_PONG, &WorldSession::_HandlePongOpcode}, {SMSG_PONG, &WorldSession::_HandlePongOpcode},
{SMSG_TRADE_STATUS, &WorldSession::_HandleTradeStatusOpcode}, {SMSG_TRADE_STATUS, &WorldSession::_HandleTradeStatusOpcode},
{SMSG_GROUP_INVITE, &WorldSession::_HandleGroupInviteOpcode}, {SMSG_GROUP_INVITE, &WorldSession::_HandleGroupInviteOpcode},
{SMSG_CHANNEL_NOTIFY, &WorldSession::_HandleChannelNotifyOpcode}, {SMSG_CHANNEL_NOTIFY, &WorldSession::_HandleChannelNotifyOpcode},
// movement opcodes // movement opcodes
{MSG_MOVE_SET_FACING, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_SET_FACING, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_FORWARD, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_FORWARD, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_BACKWARD, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_BACKWARD, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_STOP, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_STOP, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_STRAFE_LEFT, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_STRAFE_LEFT, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_STRAFE_RIGHT, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_STRAFE_RIGHT, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_STOP_STRAFE, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_STOP_STRAFE, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_JUMP, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_JUMP, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_TURN_LEFT, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_TURN_LEFT, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_TURN_RIGHT, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_TURN_RIGHT, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_STOP_TURN, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_STOP_TURN, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_START_SWIM, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_START_SWIM, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_STOP_SWIM, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_STOP_SWIM, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_HEARTBEAT, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_HEARTBEAT, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_FALL_LAND, &WorldSession::_HandleMovementOpcode}, {MSG_MOVE_FALL_LAND, &WorldSession::_HandleMovementOpcode},
{MSG_MOVE_TELEPORT_ACK, &WorldSession::_HandleTelePortAckOpcode}, {MSG_MOVE_TELEPORT_ACK, &WorldSession::_HandleTelePortAckOpcode},
{SMSG_COMPRESSED_UPDATE_OBJECT, &WorldSession::_HandleCompressedUpdateObjectOpcode}, {SMSG_COMPRESSED_UPDATE_OBJECT, &WorldSession::_HandleCompressedUpdateObjectOpcode},
{SMSG_UPDATE_OBJECT, &WorldSession::_HandleUpdateObjectOpcode}, {SMSG_UPDATE_OBJECT, &WorldSession::_HandleUpdateObjectOpcode},
{SMSG_CAST_RESULT, &WorldSession::_HandleCastResultOpcode}, {SMSG_CAST_RESULT, &WorldSession::_HandleCastResultOpcode},
{SMSG_ITEM_QUERY_SINGLE_RESPONSE, &WorldSession::_HandleItemQuerySingleResponseOpcode}, {SMSG_ITEM_QUERY_SINGLE_RESPONSE, &WorldSession::_HandleItemQuerySingleResponseOpcode},
{SMSG_DESTROY_OBJECT, &WorldSession::_HandleDestroyObjectOpcode}, {SMSG_DESTROY_OBJECT, &WorldSession::_HandleDestroyObjectOpcode},
{SMSG_INITIAL_SPELLS, &WorldSession::_HandleInitialSpellsOpcode}, {SMSG_INITIAL_SPELLS, &WorldSession::_HandleInitialSpellsOpcode},
// table termination // table termination
{ 0, NULL } { 0, NULL }
}; };
return table; return table;
} }
void WorldSession::SetTarget(uint64 guid) void WorldSession::SetTarget(uint64 guid)
{ {
_targetGUID=guid; _targetGUID=guid;
// TODO: update the UpdateFields once implemented // TODO: update the UpdateFields once implemented
} }
void WorldSession::SetFollowTarget(uint64 guid) void WorldSession::SetFollowTarget(uint64 guid)
{ {
_followGUID=guid; _followGUID=guid;
} }
void WorldSession::_OnEnterWorld(void) void WorldSession::_OnEnterWorld(void)
{ {
if(!_logged) if(!_logged)
{ {
_logged=true; _logged=true;
GetInstance()->GetScripts()->RunScript("_enterworld",NULL); GetInstance()->GetScripts()->RunScript("_enterworld",NULL);
} }
} }
void WorldSession::_OnLeaveWorld(void) void WorldSession::_OnLeaveWorld(void)
{ {
if(_logged) if(_logged)
{ {
_logged=false; _logged=false;
GetInstance()->GetScripts()->RunScript("_leaveworld",NULL); GetInstance()->GetScripts()->RunScript("_leaveworld",NULL);
} }
} }
void WorldSession::_DoTimedActions(void) void WorldSession::_DoTimedActions(void)
{ {
static clock_t pingtime=0; static clock_t pingtime=0;
if(_logged) if(_logged)
{ {
if(pingtime < clock()) if(pingtime < clock())
{ {
pingtime=clock() + 30*CLOCKS_PER_SEC; pingtime=clock() + 30*CLOCKS_PER_SEC;
SendPing(clock()); SendPing(clock());
} }
//... //...
} }
} }
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Opcode Handlers // Opcode Handlers
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
void WorldSession::_HandleAuthChallengeOpcode(WorldPacket& recvPacket) void WorldSession::_HandleAuthChallengeOpcode(WorldPacket& recvPacket)
{ {
std::string acc = stringToUpper(GetInstance()->GetConf()->accname); std::string acc = stringToUpper(GetInstance()->GetConf()->accname);
@ -279,8 +279,8 @@ void WorldSession::_HandleAuthChallengeOpcode(WorldPacket& recvPacket)
} }
void WorldSession::_HandleAuthResponseOpcode(WorldPacket& recvPacket) void WorldSession::_HandleAuthResponseOpcode(WorldPacket& recvPacket)
{ {
uint8 errcode; uint8 errcode;
recvPacket >> errcode; recvPacket >> errcode;
if(errcode==0xC){ if(errcode==0xC){
@ -291,11 +291,11 @@ void WorldSession::_HandleAuthResponseOpcode(WorldPacket& recvPacket)
} else { } else {
logcritical("World Authentication failed, errcode=0x%X",(unsigned char)errcode); logcritical("World Authentication failed, errcode=0x%X",(unsigned char)errcode);
GetInstance()->SetError(); GetInstance()->SetError();
} }
} }
void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
{ {
uint8 num; uint8 num;
PlayerEnum plr[10]; // max characters per realm is 10 PlayerEnum plr[10]; // max characters per realm is 10
uint8 dummy8; uint8 dummy8;
@ -373,10 +373,10 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket)
pkt.SetOpcode(CMSG_PLAYER_LOGIN); pkt.SetOpcode(CMSG_PLAYER_LOGIN);
pkt << _myGUID; pkt << _myGUID;
SendWorldPacket(pkt); SendWorldPacket(pkt);
} }
} }
void WorldSession::_HandleSetProficiencyOpcode(WorldPacket& recvPacket) void WorldSession::_HandleSetProficiencyOpcode(WorldPacket& recvPacket)
{ {
_OnEnterWorld(); _OnEnterWorld();
@ -572,16 +572,16 @@ void WorldSession::_HandleTradeStatusOpcode(WorldPacket& recvPacket)
} }
} }
void WorldSession::_HandleGroupInviteOpcode(WorldPacket& recvPacket) void WorldSession::_HandleGroupInviteOpcode(WorldPacket& recvPacket)
{ {
recvPacket.hexlike(); recvPacket.hexlike();
WorldPacket pkt; WorldPacket pkt;
pkt.SetOpcode(CMSG_GROUP_DECLINE); pkt.SetOpcode(CMSG_GROUP_DECLINE);
SendWorldPacket(pkt); SendWorldPacket(pkt);
} }
void WorldSession::_HandleMovementOpcode(WorldPacket& recvPacket) void WorldSession::_HandleMovementOpcode(WorldPacket& recvPacket)
{ {
uint32 flags, time; uint32 flags, time;
float x, y, z, o; float x, y, z, o;
uint64 guid; uint64 guid;
@ -619,7 +619,7 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket)
logdetail("Got teleported, data: x: %f, y: %f, z: %f, o: %f, guid: %d\n", x, y, z, o, guid); logdetail("Got teleported, data: x: %f, y: %f, z: %f, o: %f, guid: %d\n", x, y, z, o, guid);
WorldPacket response; WorldPacket response;
response.SetOpcode(MSG_MOVE_FALL_LAND); response.SetOpcode(MSG_MOVE_FALL_LAND);
response << uint32(0) << uint32(0) << x << y << z << o << uint32(0); response << uint32(0) << uint32(0) << x << y << z << o << uint32(0);
SendWorldPacket(response); SendWorldPacket(response);
} }

View File

@ -10,33 +10,33 @@ WorldSocket::WorldSocket(SocketHandler &h, WorldSession *s) : TcpSocket(h)
} }
void WorldSocket::OnConnect() void WorldSocket::OnConnect()
{ {
printf("Connected to world server.\r\n"); printf("Connected to world server.\r\n");
} }
void WorldSocket::OnConnectFailed() void WorldSocket::OnConnectFailed()
{ {
printf("WorldSocket::OnConnectFailed()\n"); printf("WorldSocket::OnConnectFailed()\n");
} }
void WorldSocket::OnDelete() void WorldSocket::OnDelete()
{ {
printf("Connection to world server has been closed.\n"); printf("Connection to world server has been closed.\n");
if(_session) if(_session)
_session->SetSocket(NULL); _session->SetSocket(NULL);
} }
void WorldSocket::OnException() void WorldSocket::OnException()
{ {
this->SetCloseAndDelete(); this->SetCloseAndDelete();
} }
void WorldSocket::OnRead() void WorldSocket::OnRead()
{ {
TcpSocket::OnRead(); TcpSocket::OnRead();
uint32 len = ibuf.GetLength(); uint32 len = ibuf.GetLength();
//printf("WorldSocket::OnRead() %u bytes\n",len); printf("WorldSocket::OnRead() %u bytes\n",len);
if(!len) if(!len)
{ {
this->CloseAndDelete(); this->CloseAndDelete();
@ -116,7 +116,7 @@ void WorldSocket::SendWorldPacket(WorldPacket &pkt)
_crypt.EncryptSend((uint8*)&hdr, 6); _crypt.EncryptSend((uint8*)&hdr, 6);
ByteBuffer final(pkt.size()+6); ByteBuffer final(pkt.size()+6);
final.append((uint8*)&hdr,sizeof(ClientPktHeader)); final.append((uint8*)&hdr,sizeof(ClientPktHeader));
final.append(pkt.contents(),pkt.size()); final.append(pkt);
SendBuf((char*)final.contents(),final.size()); SendBuf((char*)final.contents(),final.size());
} }