Example #1
0
void ClusterInterface::HandlePlayerLogin(WorldPacket & pck)
{
	/* player x logging into instance y */
	uint32 Guid, InstanceId, MapId;
	uint32 AccountId, Account_Flags, sessionid, ClientBuild;
	string GMPermissions, accountname;
	pck >> Guid >> MapId >> InstanceId >> AccountId >> Account_Flags >> sessionid >> GMPermissions >> accountname >> ClientBuild;

	/* find the instance */
	Map* ma = sInstanceMgr.GetMap(MapId);
	ASSERT(ma);
	MapMgr* mm = sInstanceMgr.GetInstance(MapId, InstanceId);
	ASSERT(mm);

	/* create the session */
	WorldSession * s = sWorld.FindSession(AccountId);

	/* create the socket */
	WorldSocket * so = new WorldSocket(sessionid);
	if (s == NULL)
		s = new WorldSession(AccountId, accountname, so);
	_sessions[sessionid] = s;
	sWorld.AddSession(s);

	bool login_result = s->ClusterTryPlayerLogin(Guid, ClientBuild, GMPermissions, Account_Flags);
	if(login_result)
	{
		/* login was ok. send a message to the realm server telling him to distribute our info to all other realm server */
		WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5);
		data << Guid << sessionid <<  uint8(1);
		SendPacket(&data);
	}
	else
	{
		/* for some reason the login failed */
		WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5);
		data << Guid << sessionid << uint8(0);
		SendPacket(&data);

		/* tell the client his login failed before deleting the session */
		data.Initialize(SMSG_CHARACTER_LOGIN_FAILED);
		data << uint8(62);
		so->SendPacket(&data);

		/* destroy the session */
		DestroySession(sessionid);
	}
}