mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Initial work on global tab list, still mostly broken.
This commit is contained in:
parent
42c03d2b77
commit
ecde4fa3a6
@ -58,7 +58,7 @@ namespace MCGalaxy.Commands
|
||||
Player.GlobalMessage("-" + p.ColoredName + "%S- is no longer AFK");
|
||||
Server.IRC.Say(p.DisplayName + " is no longer AFK");
|
||||
}
|
||||
TabList.UpdateToLevel(p, true);
|
||||
TabList.Update(p, true);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -126,7 +126,7 @@ namespace MCGalaxy {
|
||||
|
||||
public void SendRaw(byte[] buffer, bool sync = false) {
|
||||
// Abort if socket has been closed
|
||||
if (socket == null || !socket.Connected) return;
|
||||
if (disconnected || socket == null || !socket.Connected) return;
|
||||
|
||||
try {
|
||||
if (sync)
|
||||
|
@ -64,12 +64,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
internal static void Spawn(Player dst, Player p, byte id, ushort x, ushort y, ushort z,
|
||||
byte rotx, byte roty, string possession = "") {
|
||||
TabList.Add(dst, p, id);
|
||||
if (!Server.TablistGlobal)
|
||||
TabList.Add(dst, p, id);
|
||||
if (!Server.zombie.Running || !p.Game.Infected) {
|
||||
string col = GetSupportedCol(dst, p.color);
|
||||
if (dst.hasExtList) {
|
||||
@ -101,13 +100,14 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
/// <summary> Spawns this player to all other players, and spawns all others players to this player. </summary>
|
||||
internal static void SpawnEntities(Player p, ushort x, ushort y, ushort z, byte rotX, byte rotY,bool bots = true) {
|
||||
internal static void SpawnEntities(Player p, ushort x, ushort y, ushort z, byte rotX, byte rotY, bool bots = true) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != p.level || !CanSeeEntity(p, pl) || p == pl) continue;
|
||||
Spawn(p, pl, pl.id, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], "");
|
||||
}
|
||||
GlobalSpawn(p, x, y, z, rotX, rotY, true);
|
||||
TabList.UpdateToAll(p, true);
|
||||
|
||||
if (!bots) return;
|
||||
PlayerBot[] botsList = PlayerBot.Bots.Items;
|
||||
@ -122,11 +122,12 @@ namespace MCGalaxy {
|
||||
if (p.level == pl.level && p != pl) Despawn(p, pl.id);
|
||||
}
|
||||
GlobalDespawn(p, true, true);
|
||||
TabList.RemoveFromAll(p, true);
|
||||
|
||||
if (!bots) return;
|
||||
PlayerBot[] botsList = PlayerBot.Bots.Items;
|
||||
foreach (PlayerBot b in botsList) {
|
||||
if (p.level == b.level) Despawn(p, b.id);
|
||||
if (p.level == b.level) Despawn(p, b);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +142,13 @@ namespace MCGalaxy {
|
||||
|
||||
internal static void Despawn(Player dst, byte id) {
|
||||
dst.SendRaw(Opcode.RemoveEntity, id);
|
||||
TabList.Remove(dst, id);
|
||||
if (!Server.TablistGlobal)
|
||||
TabList.Remove(dst, id);
|
||||
}
|
||||
|
||||
internal static void Despawn(Player dst, PlayerBot b) {
|
||||
dst.SendRaw(Opcode.RemoveEntity, b.id);
|
||||
TabList.Remove(dst, b.id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1007,7 +1007,7 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { }
|
||||
IsAfk = false;
|
||||
Player.GlobalMessage("-" + ColoredName + "%S- is no longer AFK");
|
||||
Server.IRC.Say(DisplayName + " is no longer AFK");
|
||||
TabList.UpdateToLevel(this, true);
|
||||
TabList.Update(this, true);
|
||||
}
|
||||
// Typing //Command appears in chat as /command
|
||||
// Suggested by McMrCat
|
||||
|
@ -556,7 +556,6 @@ namespace MCGalaxy {
|
||||
return;
|
||||
}
|
||||
// FlyBuffer.Clear();
|
||||
disconnected = true;
|
||||
SaveIgnores();
|
||||
pingTimer.Stop();
|
||||
pingTimer.Dispose();
|
||||
@ -573,6 +572,7 @@ namespace MCGalaxy {
|
||||
aiming = false;
|
||||
|
||||
SendKick(kickMsg, sync);
|
||||
disconnected = true;
|
||||
if (!loggedIn) {
|
||||
connections.Remove(this);
|
||||
RemoveFromPending();
|
||||
@ -589,7 +589,7 @@ namespace MCGalaxy {
|
||||
tntwarsgame.SendAllPlayersMessage("TNT Wars: " + ColoredName + " %Shas left TNT Wars!");
|
||||
}
|
||||
|
||||
Entities.GlobalDespawn(this, false, true);
|
||||
Entities.DespawnEntities(this, false);
|
||||
if (discMsg != null) {
|
||||
if (!hidden) {
|
||||
string leavem = "&c- " + FullName + " %S" + discMsg;
|
||||
|
@ -23,24 +23,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Contains methods related to the management of tab list of player names. </summary>
|
||||
public static class TabList {
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) in the player's world. </summary>
|
||||
internal static void UpdateToLevel(Player p, bool self) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
p.Game.lastSpawnColor = p.Game.Infected ? ZombieGame.InfectCol : p.color;
|
||||
|
||||
foreach (Player other in players) {
|
||||
if ((other.Loading && p != other) || p.level != other.level) continue;
|
||||
|
||||
if (p != other && Entities.CanSeeEntity(other, p)) {
|
||||
Add(other, p, p.id);
|
||||
} else if (p == other && self) {
|
||||
Add(other, p, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Want nobody to be at top of list, banned to be bottom of list.
|
||||
// Want nobody to be at top of list, banned to be bottom of list.
|
||||
const LevelPermission offset = LevelPermission.Nobody;
|
||||
|
||||
/// <summary> Adds the given player to that player's tab list (if their client supports it). </summary>
|
||||
@ -48,21 +31,25 @@ namespace MCGalaxy {
|
||||
if (!dst.hasExtList) return;
|
||||
byte grpPerm = (byte)(offset - p.group.Permission);
|
||||
if (!Server.TablistRankSorted) grpPerm = 0;
|
||||
string col = Entities.GetSupportedCol(dst, p.color);
|
||||
|
||||
if (p.IsAfk) {
|
||||
dst.SendExtAddPlayerName(id, p.truename, col + p.truename, "&7AFK", grpPerm);
|
||||
return;
|
||||
}
|
||||
string name = col + p.truename;
|
||||
string group = "&fPlayers";
|
||||
|
||||
IGame game = p.level.CurrentGame();
|
||||
if (game != null)
|
||||
game.GetTabName(p, dst, ref name, ref group);
|
||||
string name, group;
|
||||
GetEntry(p, dst, out name, out group);
|
||||
dst.SendExtAddPlayerName(id, p.truename, name, group, grpPerm);
|
||||
}
|
||||
|
||||
/// <summary> Gets the name and the group name for the given player. </summary>
|
||||
public static void GetEntry(Player p, Player dst, out string name, out string group) {
|
||||
string col = Entities.GetSupportedCol(dst, p.color);
|
||||
if (p.IsAfk) {
|
||||
name = col + p.truename; group = "&7AFK"; return;
|
||||
}
|
||||
|
||||
name = col + p.truename;
|
||||
group = Server.TablistGlobal ? "Level " + p.level.name : "&fPlayers";
|
||||
IGame game = p.level.CurrentGame();
|
||||
if (game != null) game.GetTabName(p, dst, ref name, ref group);
|
||||
}
|
||||
|
||||
/// <summary> Adds the given bot to that player's tab list (if their client support it). </summary>
|
||||
public static void Add(Player dst, PlayerBot b) {
|
||||
if (!dst.hasExtList) return;
|
||||
@ -74,5 +61,57 @@ namespace MCGalaxy {
|
||||
if (!dst.hasExtList) return;
|
||||
dst.SendExtRemovePlayerName(id);
|
||||
}
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) who can see the player in the tab list. </summary>
|
||||
internal static void Update(Player p, bool self) {
|
||||
if (Server.TablistGlobal) UpdateToAll(p, self);
|
||||
else UpdateToLevel(p, self);
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) in the server. </summary>
|
||||
internal static void UpdateToAll(Player p, bool self) {
|
||||
if (!Server.TablistGlobal) return;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player other in players) {
|
||||
if (p != other && Entities.CanSeeEntity(other, p)) {
|
||||
Add(other, p, p.id);
|
||||
} else if (p == other && self) {
|
||||
Add(other, p, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) in the server. </summary>
|
||||
internal static void RemoveFromAll(Player p, bool self) {
|
||||
if (!Server.TablistGlobal) return;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player other in players) {
|
||||
if (p != other && Entities.CanSeeEntity(other, p)) {
|
||||
Remove(other, p.id);
|
||||
} else if (p == other && self) {
|
||||
Remove(other, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) in the player's world. </summary>
|
||||
internal static void UpdateToLevel(Player p, bool self) {
|
||||
if (Server.TablistGlobal) return;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player other in players) {
|
||||
if ((other.Loading && p != other) || p.level != other.level) continue;
|
||||
|
||||
if (p != other && Entities.CanSeeEntity(other, p)) {
|
||||
Add(other, p, p.id);
|
||||
} else if (p == other && self) {
|
||||
Add(other, p, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user