Remade who list processing
Port From (https://github.com/TrinityCore/TrinityCore/commit/07d02d744f9ac82b0543559a15ace7b3035fdb99)
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Framework.Constants;
|
||||||
|
using Game.Entities;
|
||||||
|
using Game.Guilds;
|
||||||
|
|
||||||
|
namespace Game.DataStorage
|
||||||
|
{
|
||||||
|
public class WhoListPlayerInfo
|
||||||
|
{
|
||||||
|
public WhoListPlayerInfo(ObjectGuid guid, Team team, AccountTypes security, uint level, Class clss, Race race, uint zoneid, byte gender, bool visible, bool gamemaster, string playerName, string guildName, ObjectGuid guildguid)
|
||||||
|
{
|
||||||
|
Guid = guid;
|
||||||
|
Team = team;
|
||||||
|
Security = security;
|
||||||
|
Level = level;
|
||||||
|
Class = (byte)clss;
|
||||||
|
Race = (byte)race;
|
||||||
|
ZoneId = zoneid;
|
||||||
|
Gender = gender;
|
||||||
|
IsVisible = visible;
|
||||||
|
IsGamemaster = gamemaster;
|
||||||
|
PlayerName = playerName;
|
||||||
|
GuildName = guildName;
|
||||||
|
GuildGuid = guildguid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectGuid Guid { get; }
|
||||||
|
public Team Team { get; }
|
||||||
|
public AccountTypes Security { get; }
|
||||||
|
public uint Level { get; }
|
||||||
|
public byte Class { get; }
|
||||||
|
public byte Race { get; }
|
||||||
|
public uint ZoneId { get; }
|
||||||
|
public byte Gender { get; }
|
||||||
|
public bool IsVisible { get; }
|
||||||
|
public bool IsGamemaster { get; }
|
||||||
|
public string PlayerName { get; }
|
||||||
|
public string GuildName { get; }
|
||||||
|
public ObjectGuid GuildGuid { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WhoListStorageManager : Singleton<WhoListStorageManager>
|
||||||
|
{
|
||||||
|
List<WhoListPlayerInfo> _whoListStorage;
|
||||||
|
|
||||||
|
WhoListStorageManager()
|
||||||
|
{
|
||||||
|
_whoListStorage = new List<WhoListPlayerInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
// clear current list
|
||||||
|
_whoListStorage.Clear();
|
||||||
|
|
||||||
|
var players = Global.ObjAccessor.GetPlayers();
|
||||||
|
foreach (var player in players)
|
||||||
|
{
|
||||||
|
if (player.GetMap() == null || player.GetSession().PlayerLoading())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string playerName = player.GetName();
|
||||||
|
string guildName = Global.GuildMgr.GetGuildNameById((uint)player.GetGuildId());
|
||||||
|
|
||||||
|
Guild guild = player.GetGuild();
|
||||||
|
ObjectGuid guildGuid = ObjectGuid.Empty;
|
||||||
|
|
||||||
|
if (guild)
|
||||||
|
guildGuid = guild.GetGUID();
|
||||||
|
|
||||||
|
_whoListStorage.Add(new WhoListPlayerInfo(player.GetGUID(), player.GetTeam(), player.GetSession().GetSecurity(), player.getLevel(),
|
||||||
|
player.GetClass(), player.GetRace(), player.GetZoneId(), player.m_playerData.NativeSex, player.IsVisible(),
|
||||||
|
player.IsGameMaster(), playerName, guildName, guildGuid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WhoListPlayerInfo> GetWhoList() { return _whoListStorage; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,7 @@ public static class Global
|
|||||||
//Social
|
//Social
|
||||||
public static CalendarManager CalendarMgr { get { return CalendarManager.Instance; } }
|
public static CalendarManager CalendarMgr { get { return CalendarManager.Instance; } }
|
||||||
public static SocialManager SocialMgr { get { return SocialManager.Instance; } }
|
public static SocialManager SocialMgr { get { return SocialManager.Instance; } }
|
||||||
|
public static WhoListStorageManager WhoListStorageMgr { get { return WhoListStorageManager.Instance; } }
|
||||||
|
|
||||||
//Scripts
|
//Scripts
|
||||||
public static ScriptManager ScriptMgr { get { return ScriptManager.Instance; } }
|
public static ScriptManager ScriptMgr { get { return ScriptManager.Instance; } }
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
public partial class WorldSession
|
public partial class WorldSession
|
||||||
{
|
{
|
||||||
[WorldPacketHandler(ClientOpcodes.Who)]
|
[WorldPacketHandler(ClientOpcodes.Who, Processing = PacketProcessing.ThreadSafe)]
|
||||||
void HandleWho(WhoRequestPkt whoRequest)
|
void HandleWho(WhoRequestPkt whoRequest)
|
||||||
{
|
{
|
||||||
WhoRequest request = whoRequest.Request;
|
WhoRequest request = whoRequest.Request;
|
||||||
@@ -66,61 +66,53 @@ namespace Game
|
|||||||
uint gmLevelInWhoList = WorldConfig.GetUIntValue(WorldCfg.GmLevelInWhoList);
|
uint gmLevelInWhoList = WorldConfig.GetUIntValue(WorldCfg.GmLevelInWhoList);
|
||||||
|
|
||||||
WhoResponsePkt response = new WhoResponsePkt();
|
WhoResponsePkt response = new WhoResponsePkt();
|
||||||
foreach (var target in Global.ObjAccessor.GetPlayers())
|
List<WhoListPlayerInfo> whoList = Global.WhoListStorageMgr.GetWhoList();
|
||||||
|
foreach (WhoListPlayerInfo target in whoList)
|
||||||
{
|
{
|
||||||
// player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
|
// player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
|
||||||
if (target.GetTeam() != team && !HasPermission(RBACPermissions.TwoSideWhoList))
|
if (target.Team != team && !HasPermission(RBACPermissions.TwoSideWhoList))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
|
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
|
||||||
if (target.GetSession().GetSecurity() > (AccountTypes)gmLevelInWhoList && !HasPermission(RBACPermissions.WhoSeeAllSecLevels))
|
if (target.Security > (AccountTypes)gmLevelInWhoList && !HasPermission(RBACPermissions.WhoSeeAllSecLevels))
|
||||||
continue;
|
|
||||||
|
|
||||||
// do not process players which are not in world
|
|
||||||
if (!target.IsInWorld)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if target is globally visible for player
|
// check if target is globally visible for player
|
||||||
if (!target.IsVisibleGloballyFor(GetPlayer()))
|
if (_player.GetGUID() != target.Guid && !target.IsVisible)
|
||||||
continue;
|
if (Global.AccountMgr.IsPlayerAccount(_player.GetSession().GetSecurity()) || target.Security > _player.GetSession().GetSecurity())
|
||||||
|
continue;
|
||||||
|
|
||||||
// check if target's level is in level range
|
// check if target's level is in level range
|
||||||
uint lvl = target.getLevel();
|
uint lvl = target.Level;
|
||||||
if (lvl < request.MinLevel || lvl > request.MaxLevel)
|
if (lvl < request.MinLevel || lvl > request.MaxLevel)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if class matches classmask
|
// check if class matches classmask
|
||||||
int class_ = (byte)target.GetClass();
|
if (!Convert.ToBoolean(request.ClassFilter & (1 << target.Class)))
|
||||||
if (!Convert.ToBoolean(request.ClassFilter & (1 << class_)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if race matches racemask
|
// check if race matches racemask
|
||||||
int race = (int)target.GetRace();
|
if (!Convert.ToBoolean(request.RaceFilter & (1 << target.Race)))
|
||||||
if (!Convert.ToBoolean(request.RaceFilter & (1 << race)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!whoRequest.Areas.Empty())
|
if (!whoRequest.Areas.Empty())
|
||||||
{
|
{
|
||||||
if (whoRequest.Areas.Contains((int)target.GetZoneId()))
|
if (whoRequest.Areas.Contains((int)target.ZoneId))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string wTargetName = target.GetName().ToLower();
|
string wTargetName = target.PlayerName.ToLower();
|
||||||
if (!string.IsNullOrEmpty(request.Name) && !wTargetName.Equals(request.Name))
|
if (!(request.Name.IsEmpty() || wTargetName.Equals(request.Name)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string wTargetGuildName = "";
|
string wTargetGuildName = target.GuildName.ToLower();
|
||||||
Guild targetGuild = target.GetGuild();
|
if (!request.Guild.IsEmpty() && !wTargetGuildName.Equals(request.Guild))
|
||||||
if (targetGuild)
|
|
||||||
wTargetGuildName = targetGuild.GetName().ToLower();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.Guild) && !wTargetGuildName.Equals(request.Guild))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!request.Words.Empty())
|
if (!request.Words.Empty())
|
||||||
{
|
{
|
||||||
string aname = "";
|
string aname = "";
|
||||||
AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(target.GetZoneId());
|
AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(target.ZoneId);
|
||||||
if (areaEntry != null)
|
if (areaEntry != null)
|
||||||
aname = areaEntry.AreaName[GetSessionDbcLocale()].ToLower();
|
aname = areaEntry.AreaName[GetSessionDbcLocale()].ToLower();
|
||||||
|
|
||||||
@@ -144,18 +136,18 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
WhoEntry whoEntry = new WhoEntry();
|
WhoEntry whoEntry = new WhoEntry();
|
||||||
if (!whoEntry.PlayerData.Initialize(target.GetGUID(), target))
|
if (!whoEntry.PlayerData.Initialize(target.Guid, null))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (targetGuild)
|
if (!target.GuildGuid.IsEmpty())
|
||||||
{
|
{
|
||||||
whoEntry.GuildGUID = targetGuild.GetGUID();
|
whoEntry.GuildGUID = target.GuildGuid;
|
||||||
whoEntry.GuildVirtualRealmAddress = Global.WorldMgr.GetVirtualRealmAddress();
|
whoEntry.GuildVirtualRealmAddress = Global.WorldMgr.GetVirtualRealmAddress();
|
||||||
whoEntry.GuildName = targetGuild.GetName();
|
whoEntry.GuildName = target.GuildName;
|
||||||
}
|
}
|
||||||
|
|
||||||
whoEntry.AreaID = (int)target.GetZoneId();
|
whoEntry.AreaID = (int)target.ZoneId;
|
||||||
whoEntry.IsGM = target.IsGameMaster();
|
whoEntry.IsGM = target.IsGamemaster;
|
||||||
|
|
||||||
response.Response.Add(whoEntry);
|
response.Response.Add(whoEntry);
|
||||||
|
|
||||||
|
|||||||
@@ -858,6 +858,8 @@ namespace Game
|
|||||||
|
|
||||||
blackmarket_timer = 0;
|
blackmarket_timer = 0;
|
||||||
|
|
||||||
|
m_timers[WorldTimers.WhoList].SetInterval(5 * Time.InMilliseconds); // update who list cache every 5 seconds
|
||||||
|
|
||||||
//to set mailtimer to return mails every day between 4 and 5 am
|
//to set mailtimer to return mails every day between 4 and 5 am
|
||||||
//mailtimer is increased when updating auctions
|
//mailtimer is increased when updating auctions
|
||||||
//one second is 1000 -(tested on win system)
|
//one second is 1000 -(tested on win system)
|
||||||
@@ -1161,6 +1163,14 @@ namespace Game
|
|||||||
m_timers[i].SetCurrent(0);
|
m_timers[i].SetCurrent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update Who List Storage
|
||||||
|
if (m_timers[WorldTimers.WhoList].Passed())
|
||||||
|
{
|
||||||
|
m_timers[WorldTimers.WhoList].Reset();
|
||||||
|
Global.WhoListStorageMgr.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the game time and check for shutdown time
|
||||||
_UpdateGameTime();
|
_UpdateGameTime();
|
||||||
|
|
||||||
// Handle daily quests reset time
|
// Handle daily quests reset time
|
||||||
@@ -2473,6 +2483,7 @@ namespace Game
|
|||||||
PingDB,
|
PingDB,
|
||||||
GuildSave,
|
GuildSave,
|
||||||
Blackmarket,
|
Blackmarket,
|
||||||
|
WhoList,
|
||||||
Max
|
Max
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user