-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from balt-dev/main
/locate command
- Loading branch information
Showing
11 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Celeste.Mod.CelesteNet.DataTypes; | ||
|
||
namespace Celeste.Mod.CelesteNet.Client { | ||
public class CelesteNetLocationInfo { | ||
|
||
public string SID { get; set; } | ||
public AreaData Area { get; set; } | ||
public string Name { get; set; } | ||
public string Side { get; set; } | ||
public string Level { get; set; } | ||
public string Icon { get; set; } | ||
public string EmoteID => string.IsNullOrWhiteSpace(SID) ? "" : $"celestenet_SID_{SID}_"; | ||
|
||
private bool emoteLoaded = false; | ||
public string Emote => LoadIconEmote() ? $":{EmoteID}:" : ""; | ||
public bool IsRandomizer => Name.StartsWith("randomizer/"); | ||
|
||
public CelesteNetLocationInfo() { } | ||
|
||
public CelesteNetLocationInfo(string sid) { | ||
SID = sid; | ||
Area = AreaData.Get(SID); | ||
|
||
Name = Area?.Name?.DialogCleanOrNull(Dialog.Languages["english"]) ?? SID; | ||
Side = "A"; | ||
Level = ""; | ||
Icon = ""; | ||
|
||
if (!IsRandomizer && Area != null) { | ||
Icon = Area.Icon; | ||
|
||
string lobbySID = Area?.Meta?.Parent; | ||
AreaData lobby = string.IsNullOrEmpty(lobbySID) ? null : AreaData.Get(lobbySID); | ||
if (lobby?.Icon != null) | ||
Icon = lobby.Icon; | ||
} | ||
} | ||
|
||
public CelesteNetLocationInfo(DataPlayerState state) : this(state?.SID) { | ||
|
||
if (state != null) { | ||
Side = ((char)('A' + (int)state.Mode)).ToString(); | ||
Level = state.Level; | ||
} | ||
} | ||
|
||
public bool LoadIconEmote() { | ||
if (emoteLoaded) | ||
return true; | ||
|
||
if ( | ||
// Icon exists | ||
!string.IsNullOrWhiteSpace(Icon) && | ||
// Can construct Emoji ID | ||
!string.IsNullOrWhiteSpace(EmoteID) && | ||
// Icon is loaded | ||
GFX.Gui.Has(Icon) | ||
) { | ||
if (!Emoji.Registered.Contains(EmoteID)) { | ||
// We need to downscale the icon to fit in chat | ||
// Due to our previous checks, this is never null | ||
Monocle.MTexture icon = GFX.Gui[Icon]; | ||
float scale = 64f / icon.Height; | ||
|
||
Monocle.MTexture tex = new(new(icon.Texture), icon.ClipRect) { ScaleFix = scale }; | ||
Emoji.Register(EmoteID, tex); | ||
Emoji.Fill(CelesteNetClientFont.Font); | ||
} | ||
emoteLoaded = Emoji.Registered.Contains(EmoteID); | ||
} | ||
return emoteLoaded; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Celeste.Mod.CelesteNet.DataTypes; | ||
|
||
namespace Celeste.Mod.CelesteNet.Server.Chat.Cmd; | ||
|
||
public class CmdLocate : ChatCmd { | ||
|
||
public override CompletionType Completion => CompletionType.Player; | ||
|
||
public override string Info => "Find where a player is."; | ||
|
||
public override CelesteNetSupportedClientFeatures RequiredFeatures => | ||
CelesteNetSupportedClientFeatures.LocateCommand; | ||
|
||
private CelesteNetPlayerSession? Other; | ||
private DataPlayerInfo? OtherPlayer; | ||
|
||
public override void Init(ChatModule chat) { | ||
Chat = chat; | ||
|
||
ArgParser parser = new(chat, this); | ||
parser.AddParameter(new ParamPlayerSession(chat, ValidatePlayerSession)); | ||
ArgParsers.Add(parser); | ||
} | ||
|
||
private void ValidatePlayerSession(string raw, CmdEnv env, ICmdArg arg) { | ||
if (arg is not CmdArgPlayerSession sessionArg) | ||
throw new CommandRunException("Invalid username or ID."); | ||
|
||
CelesteNetPlayerSession? other = sessionArg.Session; | ||
DataPlayerInfo otherPlayer = other?.PlayerInfo ?? throw new CommandRunException("Invalid username or ID."); | ||
|
||
Other = other; | ||
OtherPlayer = otherPlayer; | ||
} | ||
|
||
|
||
public override void Run(CmdEnv env, List<ICmdArg>? args) { | ||
if (Other == null || OtherPlayer == null) | ||
throw new InvalidOperationException("This should never happen if ValidatePlayerSession returns without error."); | ||
|
||
CelesteNetPlayerSession? self = env.Session ?? throw new CommandRunException("Cannot locate as the server."); | ||
|
||
var chat = new DataChat { | ||
Player = OtherPlayer, | ||
Tag = "locate", | ||
// On older clients, we never get here. On newer clients, this is replaced. | ||
Text = "{YOU SHOULD NEVER SEE THIS, PLEASE REPORT}", | ||
Color = Chat.Settings.ColorCommandReply | ||
}; | ||
self.Con.Send(chat); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters