mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Add some comments to PlayerInfo class.
This commit is contained in:
parent
7b50b25c8a
commit
b16c64eb62
@ -67,7 +67,7 @@ namespace MCGalaxy.Commands {
|
|||||||
Player.Message(p, "That player is either following someone or already possessed."); return;
|
Player.Message(p, "That player is either following someone or already possessed."); return;
|
||||||
}
|
}
|
||||||
if (p.possess != "") {
|
if (p.possess != "") {
|
||||||
Player prev = PlayerInfo.Find(p.possess);
|
Player prev = PlayerInfo.FindExact(p.possess);
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
prev.following = "";
|
prev.following = "";
|
||||||
prev.canBuild = true;
|
prev.canBuild = true;
|
||||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy.Gui {
|
|||||||
|
|
||||||
UpdateListTimer.Elapsed += delegate {
|
UpdateListTimer.Elapsed += delegate {
|
||||||
try {
|
try {
|
||||||
UpdateClientList(PlayerInfo.players);
|
UpdateClientList(Player.players);
|
||||||
UpdateMapList();
|
UpdateMapList();
|
||||||
}
|
}
|
||||||
catch { } // needed for slower computers
|
catch { } // needed for slower computers
|
||||||
@ -219,14 +219,14 @@ namespace MCGalaxy.Gui {
|
|||||||
//dgvPlayers.SuspendLayout();
|
//dgvPlayers.SuspendLayout();
|
||||||
|
|
||||||
pc = new PlayerCollection();
|
pc = new PlayerCollection();
|
||||||
PlayerInfo.players.ForEach(p => pc.Add(p));
|
Player.players.ForEach(p => pc.Add(p));
|
||||||
|
|
||||||
//dgvPlayers.Invalidate();
|
//dgvPlayers.Invalidate();
|
||||||
main_Players.DataSource = pc;
|
main_Players.DataSource = pc;
|
||||||
// Reselect player
|
// Reselect player
|
||||||
if (selected != null)
|
if (selected != null)
|
||||||
{
|
{
|
||||||
foreach (Player t in PlayerInfo.players)
|
foreach (Player t in Player.players)
|
||||||
for (int j = 0; j < main_Players.Rows.Count; j++)
|
for (int j = 0; j < main_Players.Rows.Count; j++)
|
||||||
if (Equals(main_Players.Rows[j].Cells[0].Value, selected))
|
if (Equals(main_Players.Rows[j].Cells[0].Value, selected))
|
||||||
main_Players.Rows[j].Selected = true;
|
main_Players.Rows[j].Selected = true;
|
||||||
@ -536,7 +536,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoginBt_Click(object sender, EventArgs e) {
|
void LoginBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
CP437Writer.WriteAllText("text/login/" + curPlayer.name + ".txt", pl_txtLogin.Text);
|
CP437Writer.WriteAllText("text/login/" + curPlayer.name + ".txt", pl_txtLogin.Text);
|
||||||
@ -544,7 +544,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LogoutBt_Click(object sender, EventArgs e) {
|
void LogoutBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
CP437Writer.WriteAllText("text/logout/" + curPlayer.name + ".txt", pl_txtLogout.Text);
|
CP437Writer.WriteAllText("text/logout/" + curPlayer.name + ".txt", pl_txtLogout.Text);
|
||||||
@ -552,7 +552,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TitleBt_Click(object sender, EventArgs e) {
|
void TitleBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
if (pl_txtTitle.Text.Length > 17) { PlayersTextBox.AppendTextAndScroll("Title must be under 17 letters."); return; }
|
if (pl_txtTitle.Text.Length > 17) { PlayersTextBox.AppendTextAndScroll("Title must be under 17 letters."); return; }
|
||||||
@ -561,7 +561,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ColorBt_Click(object sender, EventArgs e) {
|
void ColorBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
curPlayer.color = Colors.Parse(pl_cmbColor.Text);
|
curPlayer.color = Colors.Parse(pl_cmbColor.Text);
|
||||||
@ -569,7 +569,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MapBt_Click(object sender, EventArgs e) {
|
void MapBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
if (pl_cmbMap.Text.ToLower() == curPlayer.level.name.ToLower()) {
|
if (pl_cmbMap.Text.ToLower() == curPlayer.level.name.ToLower()) {
|
||||||
@ -588,7 +588,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UndoBt_Click(object sender, EventArgs e) {
|
void UndoBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
if (pl_txtUndo.Text.Trim() == "") {
|
if (pl_txtUndo.Text.Trim() == "") {
|
||||||
@ -604,7 +604,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessageBt_Click(object sender, EventArgs e) {
|
void MessageBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Player.SendMessage(curPlayer, "<CONSOLE> " + pl_txtMessage.Text);
|
Player.SendMessage(curPlayer, "<CONSOLE> " + pl_txtMessage.Text);
|
||||||
@ -613,7 +613,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImpersonateORSendCmdBt_Click(object sender, EventArgs e) {
|
void ImpersonateORSendCmdBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -669,7 +669,7 @@ namespace MCGalaxy.Gui {
|
|||||||
void IPBanBt_Click(object sender, EventArgs e) { DoCmd("banip", "IP-Banned"); }
|
void IPBanBt_Click(object sender, EventArgs e) { DoCmd("banip", "IP-Banned"); }
|
||||||
|
|
||||||
void DoCmd(string cmdName, string action) {
|
void DoCmd(string cmdName, string action) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Command.all.Find(cmdName).Use(null, curPlayer.name);
|
Command.all.Find(cmdName).Use(null, curPlayer.name);
|
||||||
@ -677,7 +677,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DoCmd(string cmdName, string action, string prefix) {
|
void DoCmd(string cmdName, string action, string prefix) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Command.all.Find(cmdName).Use(null, prefix + curPlayer.name);
|
Command.all.Find(cmdName).Use(null, prefix + curPlayer.name);
|
||||||
@ -686,7 +686,7 @@ namespace MCGalaxy.Gui {
|
|||||||
|
|
||||||
void DoToggle(string cmdName, Button target, string targetDesc,
|
void DoToggle(string cmdName, Button target, string targetDesc,
|
||||||
Predicate<Player> getter, string action) {
|
Predicate<Player> getter, string action) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Command.all.Find(cmdName).Use(null, curPlayer.name);
|
Command.all.Find(cmdName).Use(null, curPlayer.name);
|
||||||
@ -701,7 +701,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SendRulesTxt_Click(object sender, EventArgs e) {
|
void SendRulesTxt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Command.all.Find("rules").Use(curPlayer, "");
|
Command.all.Find("rules").Use(curPlayer, "");
|
||||||
@ -709,7 +709,7 @@ namespace MCGalaxy.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpawnBt_Click(object sender, EventArgs e) {
|
void SpawnBt_Click(object sender, EventArgs e) {
|
||||||
if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) {
|
if (curPlayer == null || !Player.players.Contains(curPlayer)) {
|
||||||
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
PlayersTextBox.AppendTextAndScroll("No Player Selected"); return;
|
||||||
}
|
}
|
||||||
Player p = curPlayer;
|
Player p = curPlayer;
|
||||||
@ -722,11 +722,9 @@ namespace MCGalaxy.Gui {
|
|||||||
|
|
||||||
public void UpdatePlyersListBox() {
|
public void UpdatePlyersListBox() {
|
||||||
RunOnUiThread(
|
RunOnUiThread(
|
||||||
delegate
|
delegate {
|
||||||
{
|
|
||||||
|
|
||||||
PlyersListBox.Items.Clear();
|
PlyersListBox.Items.Clear();
|
||||||
foreach (Player p in PlayerInfo.players)
|
foreach (Player p in Player.players)
|
||||||
{
|
{
|
||||||
PlyersListBox.Items.Add(p.name);
|
PlyersListBox.Items.Add(p.name);
|
||||||
}
|
}
|
||||||
|
@ -362,13 +362,13 @@ catch { }*/
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAloneOnCurrentLevel() {
|
public bool IsAloneOnCurrentLevel() {
|
||||||
return PlayerInfo.players.All(pl => pl.level != level || pl == this);
|
return Player.players.All(pl => pl.level != level || pl == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region == OTHER ==
|
#region == OTHER ==
|
||||||
|
|
||||||
[Obsolete("Use PlayerInfo.players")]
|
[Obsolete("Use PlayerInfo.Online.Items")]
|
||||||
public static List<Player> players;
|
public static List<Player> players;
|
||||||
|
|
||||||
[Obsolete("Use PlayerInfo.Find(name)")]
|
[Obsolete("Use PlayerInfo.Find(name)")]
|
||||||
|
@ -19,15 +19,13 @@ using System.Data;
|
|||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
|
public static class PlayerInfo {
|
||||||
public static class PlayerInfo {
|
|
||||||
public static List<Player> players;
|
|
||||||
|
|
||||||
/// <summary> Array of all currently online players. </summary>
|
/// <summary> Array of all currently online players. </summary>
|
||||||
/// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks>
|
/// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks>
|
||||||
public static VolatileArray<Player> Online = new VolatileArray<Player>(true);
|
public static VolatileArray<Player> Online = new VolatileArray<Player>(true);
|
||||||
|
[Obsolete("Use PlayerInfo.Online.Items")]
|
||||||
public static List<Player> GetPlayers() { return new List<Player>(players); }
|
public static List<Player> players;
|
||||||
|
|
||||||
public static Group GetGroup(string name) { return Group.findPlayerGroup(name); }
|
public static Group GetGroup(string name) { return Group.findPlayerGroup(name); }
|
||||||
|
|
||||||
@ -52,7 +50,8 @@ namespace MCGalaxy {
|
|||||||
int matches = 0; return FindMatches(pl, name, out matches, onlyCanSee);
|
int matches = 0; return FindMatches(pl, name, out matches, onlyCanSee);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player FindMatches(Player pl, string name, out int matches, bool onlyCanSee = true) {
|
public static Player FindMatches(Player pl, string name,
|
||||||
|
out int matches, bool onlyCanSee = true) {
|
||||||
matches = 0;
|
matches = 0;
|
||||||
if (!Player.ValidName(name)) {
|
if (!Player.ValidName(name)) {
|
||||||
Player.Message(pl, "\"{0}\" is not a valid player name.", name); return null;
|
Player.Message(pl, "\"{0}\" is not a valid player name.", name); return null;
|
||||||
@ -63,6 +62,8 @@ namespace MCGalaxy {
|
|||||||
p => p.name, "online players");
|
p => p.name, "online players");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Finds the online player whose name caselessly exactly matches the given name. </summary>
|
||||||
|
/// <returns> Player instance if an exact match is found, null if not. </returns>
|
||||||
public static Player FindExact(string name) {
|
public static Player FindExact(string name) {
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
|
|
||||||
@ -90,6 +91,9 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary> Retrieves the player data for the player whose name
|
||||||
|
/// caselessly exactly matches the given name. </summary>
|
||||||
|
/// <returns> PlayerData instance if found, null if not. </returns>
|
||||||
public static PlayerData FindData(string name) {
|
public static PlayerData FindData(string name) {
|
||||||
using (DataTable results = Query(name, "*")) {
|
using (DataTable results = Query(name, "*")) {
|
||||||
if (results.Rows.Count == 0) return null;
|
if (results.Rows.Count == 0) return null;
|
||||||
@ -97,13 +101,19 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Retrieves the actual name for the player whose name
|
||||||
|
/// caselessly exactly matches the given name. </summary>
|
||||||
|
/// <returns> Correctly cased name if found, null if not. </returns>
|
||||||
public static string FindName(string name) {
|
public static string FindName(string name) {
|
||||||
using (DataTable playerDB = Query(name, "Name")) {
|
using (DataTable playerDB = Query(name, "Name")) {
|
||||||
if (playerDB.Rows.Count == 0) return null;
|
if (playerDB.Rows.Count == 0) return null;
|
||||||
return playerDB.Rows[0]["Name"].ToString().Trim();
|
return playerDB.Rows[0]["Name"].ToString().Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Retrieves the last IP address for the player whose name
|
||||||
|
/// caselessly exactly matches the given name. </summary>
|
||||||
|
/// <returns> Last IP address if found, null if not. </returns>
|
||||||
public static string FindIP(string name) {
|
public static string FindIP(string name) {
|
||||||
using (DataTable results = Query(name, "IP")) {
|
using (DataTable results = Query(name, "IP")) {
|
||||||
if (results.Rows.Count == 0) return null;
|
if (results.Rows.Count == 0) return null;
|
||||||
@ -139,6 +149,8 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Retrieves the names of all players whose last IP address
|
||||||
|
/// matches the given IP address. </summary>
|
||||||
public static List<string> FindAccounts(string ip) {
|
public static List<string> FindAccounts(string ip) {
|
||||||
DataTable clones = Database.Fill("SELECT Name FROM Players WHERE IP=@0", ip);
|
DataTable clones = Database.Fill("SELECT Name FROM Players WHERE IP=@0", ip);
|
||||||
List<string> alts = new List<string>();
|
List<string> alts = new List<string>();
|
||||||
|
@ -60,8 +60,8 @@ namespace MCGalaxy {
|
|||||||
serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame));
|
serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame));
|
||||||
levelConfig = ConfigElement.GetAll(typeof(Level));
|
levelConfig = ConfigElement.GetAll(typeof(Level));
|
||||||
|
|
||||||
PlayerInfo.players = PlayerInfo.Online.list;
|
|
||||||
Player.players = PlayerInfo.Online.list;
|
Player.players = PlayerInfo.Online.list;
|
||||||
|
PlayerInfo.players = PlayerInfo.Online.list;
|
||||||
Server.levels = LevelInfo.Loaded.list;
|
Server.levels = LevelInfo.Loaded.list;
|
||||||
PlayerBot.playerbots = PlayerBot.Bots.list;
|
PlayerBot.playerbots = PlayerBot.Bots.list;
|
||||||
StartTime = DateTime.UtcNow;
|
StartTime = DateTime.UtcNow;
|
||||||
@ -164,7 +164,7 @@ namespace MCGalaxy {
|
|||||||
string api = "";
|
string api = "";
|
||||||
API API = new API();
|
API API = new API();
|
||||||
API.max_players = (int)Server.players;
|
API.max_players = (int)Server.players;
|
||||||
API.players = PlayerInfo.players.Select(mc => mc.name).ToArray();
|
API.players = Player.players.Select(mc => mc.name).ToArray();
|
||||||
API.chat = Player.Last50Chat.ToArray();
|
API.chat = Player.Last50Chat.ToArray();
|
||||||
api = JsonConvert.SerializeObject(API, Formatting.Indented);
|
api = JsonConvert.SerializeObject(API, Formatting.Indented);
|
||||||
return api;
|
return api;
|
||||||
@ -290,7 +290,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerListUpdate() {
|
public void PlayerListUpdate() {
|
||||||
if (Server.s.OnPlayerListChange != null) Server.s.OnPlayerListChange(PlayerInfo.players);
|
if (Server.s.OnPlayerListChange != null) Server.s.OnPlayerListChange(Player.players);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FailBeat() {
|
public void FailBeat() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user