Skip to content

Commit

Permalink
Core/Battle.net: Implemented updating realm list after initial login
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Oct 11, 2014
1 parent 35b14f1 commit 56cf7ff
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 187 deletions.
10 changes: 2 additions & 8 deletions src/server/authserver/Realms/RealmList.cpp
Expand Up @@ -77,7 +77,7 @@ void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInte
}

void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build, uint8 region, uint8 battlegroup)
ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build)
{
// Create new if not exist or update existed
Realm& realm = m_realms[name];
Expand All @@ -90,15 +90,11 @@ void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address cons
realm.allowedSecurityLevel = allowedSecurityLevel;
realm.populationLevel = population;

// Append port to IP address.

realm.ExternalAddress = address;
realm.LocalAddress = localAddr;
realm.LocalSubnetMask = localSubmask;
realm.port = port;
realm.gamebuild = build;
realm.Region = region;
realm.Battlegroup = battlegroup;
}

void RealmList::UpdateIfNeed()
Expand Down Expand Up @@ -174,11 +170,9 @@ void RealmList::UpdateRealms(bool init)
uint8 allowedSecurityLevel = fields[9].GetUInt8();
float pop = fields[10].GetFloat();
uint32 build = fields[11].GetUInt32();
uint8 region = fields[12].GetUInt8();
uint8 battlegroup = fields[13].GetUInt8();

UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone,
(allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build, region, battlegroup);
(allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);

if (init)
TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.to_string().c_str(), port);
Expand Down
4 changes: 1 addition & 3 deletions src/server/authserver/Realms/RealmList.h
Expand Up @@ -54,8 +54,6 @@ struct Realm
AccountTypes allowedSecurityLevel;
float populationLevel;
uint32 gamebuild;
uint8 Region;
uint8 Battlegroup;

ip::tcp::endpoint GetAddressForClient(ip::address const& clientAddr) const;
};
Expand Down Expand Up @@ -89,7 +87,7 @@ class RealmList

void UpdateRealms(bool init = false);
void UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build, uint8 region, uint8 battlegroup);
ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build);

RealmMap m_realms;
uint32 m_UpdateInterval;
Expand Down
9 changes: 1 addition & 8 deletions src/server/bnetserver/Main.cpp
Expand Up @@ -99,14 +99,7 @@ int main(int argc, char** argv)
return 1;

// Get the list of realms for the server
sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));

if (sRealmList->size() == 0)
{
TC_LOG_ERROR("server.bnetserver", "No valid realms specified.");
StopDB();
return 1;
}
sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));

// Start the listening port (acceptor) for auth connections
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
Expand Down
22 changes: 10 additions & 12 deletions src/server/bnetserver/Packets/FriendsPackets.cpp
Expand Up @@ -18,23 +18,22 @@
#include "Session.h"
#include "FriendsPackets.h"

void Battlenet::Friends::SocialnetworkCheckConnected::Read()
void Battlenet::Friends::SocialNetworkCheckConnected::Read()
{
SocialNetworkId = _stream.Read<uint32>(32);
}

std::string Battlenet::Friends::SocialnetworkCheckConnected::ToString() const
std::string Battlenet::Friends::SocialNetworkCheckConnected::ToString() const
{
return "Battlenet::Friends::SocialnetworkCheckConnected SocialNetworkId " + std::to_string(SocialNetworkId);
return "Battlenet::Friends::SocialNetworkCheckConnected SocialNetworkId " + std::to_string(SocialNetworkId);
}

void Battlenet::Friends::SocialnetworkCheckConnected::CallHandler(Session* session) const
void Battlenet::Friends::SocialNetworkCheckConnected::CallHandler(Session* session) const
{
SocialNetworkCheckConnectedResult* result = new SocialNetworkCheckConnectedResult(SocialNetworkId);
session->AsyncWrite(result);
session->HandleSocialNetworkCheckConnected(*this);
}

void Battlenet::Friends::SocialnetworkConnect::Read()
void Battlenet::Friends::SocialNetworkConnect::Read()
{
int32 unk1 = _stream.Read<int32>(32);
uint32 size1 = _stream.Read<uint32>(9);
Expand All @@ -43,12 +42,12 @@ void Battlenet::Friends::SocialnetworkConnect::Read()
auto data2 = _stream.ReadBytes(size2);
}

std::string Battlenet::Friends::SocialnetworkConnect::ToString() const
std::string Battlenet::Friends::SocialNetworkConnect::ToString() const
{
return "Battlenet::Friends::SocialnetworkConnect";
return "Battlenet::Friends::SocialNetworkConnect";
}

void Battlenet::Friends::SocialnetworkConnect::CallHandler(Session* session) const
void Battlenet::Friends::SocialNetworkConnect::CallHandler(Session* session) const
{
session->LogUnhandledPacket(*this);
}
Expand All @@ -70,8 +69,7 @@ std::string Battlenet::Friends::SocialNetworkCheckConnectedResult::ToString() co
void Battlenet::Friends::SocialNetworkCheckConnectedResult::Write()
{
_stream.Write(0, 23); // Ignored
volatile uint16 res = 0;
_stream.Write(res, 16); // Unknown
_stream.Write(0, 16); // Unknown
_stream.Write(SocialNetworkId, 32);
}

Expand Down
11 changes: 6 additions & 5 deletions src/server/bnetserver/Packets/FriendsPackets.h
Expand Up @@ -54,10 +54,10 @@ namespace Battlenet
SMSG_FRIENDS_LIST_NOTIFY_3 = 0x18 // Not implemented
};

class SocialnetworkConnect final : public ClientPacket
class SocialNetworkConnect final : public ClientPacket
{
public:
SocialnetworkConnect(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
SocialNetworkConnect(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_SOCIAL_NETWORK_CONNECT, FRIENDS) && "Invalid packet header for SocialnetworkConnect");
}
Expand All @@ -78,10 +78,10 @@ namespace Battlenet
std::string ToString() const override;
};

class SocialnetworkCheckConnected final : public ClientPacket
class SocialNetworkCheckConnected final : public ClientPacket
{
public:
SocialnetworkCheckConnected(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
SocialNetworkCheckConnected(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_SOCIAL_NETWORK_CHECK_CONNECTED, FRIENDS) && "Invalid packet header for SocialNetworkCheckConnected");
}
Expand All @@ -96,7 +96,8 @@ namespace Battlenet
class SocialNetworkCheckConnectedResult final : public ServerPacket
{
public:
SocialNetworkCheckConnectedResult(uint32 socialNetworkId) : ServerPacket(PacketHeader(SMSG_SOCIAL_NETWORK_CHECK_CONNECTED_RESULT, FRIENDS)), SocialNetworkId(socialNetworkId)
SocialNetworkCheckConnectedResult() : ServerPacket(PacketHeader(SMSG_SOCIAL_NETWORK_CHECK_CONNECTED_RESULT, FRIENDS)),
SocialNetworkId(0)
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/server/bnetserver/Packets/PacketFactory.h
Expand Up @@ -57,10 +57,11 @@ namespace Battlenet
_creators[PacketHeader(Connection::CMSG_LOGOUT_REQUEST, CONNECTION)] = &New<Connection::LogoutRequest>;

_creators[PacketHeader(WoWRealm::CMSG_LIST_SUBSCRIBE_REQUEST, WOWREALM)] = &New<WoWRealm::ListSubscribeRequest>;
_creators[PacketHeader(WoWRealm::CMSG_LIST_UNSUBSCRIBE, WOWREALM)] = &New<WoWRealm::ListUnsubscribe>;
_creators[PacketHeader(WoWRealm::CMSG_JOIN_REQUEST_V2, WOWREALM)] = &New<WoWRealm::JoinRequestV2>;

_creators[PacketHeader(Friends::CMSG_SOCIAL_NETWORK_CHECK_CONNECTED, FRIENDS)] = &New<Friends::SocialnetworkCheckConnected>;
_creators[PacketHeader(Friends::CMSG_SOCIAL_NETWORK_CONNECT, FRIENDS)] = &New<Friends::SocialnetworkConnect>;
_creators[PacketHeader(Friends::CMSG_SOCIAL_NETWORK_CHECK_CONNECTED, FRIENDS)] = &New<Friends::SocialNetworkCheckConnected>;
_creators[PacketHeader(Friends::CMSG_SOCIAL_NETWORK_CONNECT, FRIENDS)] = &New<Friends::SocialNetworkConnect>;
_creators[PacketHeader(Friends::CMSG_GET_FRIENDS_OF_FRIEND, FRIENDS)] = &New<Friends::GetFriendsOfFriend>;
_creators[PacketHeader(Friends::CMSG_REALID_FRIEND_INVITE, FRIENDS)] = &New<Friends::RealIdFriendInvite>;

Expand Down
20 changes: 15 additions & 5 deletions src/server/bnetserver/Packets/WoWRealmPackets.cpp
Expand Up @@ -30,6 +30,16 @@ void Battlenet::WoWRealm::ListSubscribeRequest::CallHandler(Session* session) co
session->HandleListSubscribeRequest(*this);
}

std::string Battlenet::WoWRealm::ListUnsubscribe::ToString() const
{
return "Battlenet::WoWRealm::ListUnsubscribe";
}

void Battlenet::WoWRealm::ListUnsubscribe::CallHandler(Session* session) const
{
session->HandleListUnsubscribe(*this);
}

Battlenet::WoWRealm::ListSubscribeResponse::~ListSubscribeResponse()
{
for (ServerPacket* realmData : RealmData)
Expand Down Expand Up @@ -95,7 +105,7 @@ void Battlenet::WoWRealm::ListUpdate::Write()
if (!Version.empty())
{
_stream.WriteString(Version, 5);
_stream.Write(Build, 32);
_stream.Write(Id.Build, 32);

boost::asio::ip::address_v4::bytes_type ip = Address.address().to_v4().to_bytes();
uint16 port = Address.port();
Expand All @@ -110,16 +120,16 @@ void Battlenet::WoWRealm::ListUpdate::Write()
_stream.WriteString(Name, 10);
}

_stream.Write(Battlegroup, 8);
_stream.Write(Index, 32);
_stream.Write(Region, 8);
_stream.Write(Id.Battlegroup, 8);
_stream.Write(Id.Index, 32);
_stream.Write(Id.Region, 8);
}

std::string Battlenet::WoWRealm::ListUpdate::ToString() const
{
std::ostringstream stream;
stream << "Battlenet::WoWRealm::ListUpdate Timezone " << Timezone << " Population " << Population << " Lock " << uint32(Lock) << " Type " << Type << " Name " << Name
<< " Flags " << uint32(Flags) << " Region " << uint32(Region) << " Battlegroup " << uint32(Battlegroup) << " Index " << Index;
<< " Flags " << uint32(Flags) << " Region " << uint32(Id.Region) << " Battlegroup " << uint32(Id.Battlegroup) << " Index " << Id.Index;

if (!Version.empty())
stream << " Version " << Version;
Expand Down
21 changes: 15 additions & 6 deletions src/server/bnetserver/Packets/WoWRealmPackets.h
Expand Up @@ -53,6 +53,19 @@ namespace Battlenet
void CallHandler(Session* session) const override;
};

class ListUnsubscribe final : public ClientPacket
{
public:
ListUnsubscribe(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_LIST_UNSUBSCRIBE, WOWREALM) && "Invalid packet header for ListUnsubscribe");
}

void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
};

class JoinRequestV2 final : public ClientPacket
{
public:
Expand Down Expand Up @@ -110,8 +123,7 @@ namespace Battlenet
};

ListUpdate() : ServerPacket(PacketHeader(SMSG_LIST_UPDATE, WOWREALM)), UpdateState(UPDATE),
Timezone(0), Population(0.0f), Lock(0), Type(0), Name(""), Version(""),
Flags(0), Region(0), Battlegroup(0), Index(0), Build(0)
Timezone(0), Population(0.0f), Lock(0), Type(0), Name(""), Version(""), Flags(0)
{
}

Expand All @@ -127,10 +139,7 @@ namespace Battlenet
std::string Version;
tcp::endpoint Address;
uint8 Flags;
uint8 Region;
uint8 Battlegroup;
uint32 Index;
uint32 Build;
RealmId Id;
};

class ListComplete final : public ServerPacket
Expand Down

0 comments on commit 56cf7ff

Please sign in to comment.