Skip to content

Fix major issues and perms #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,5 @@ fabric.properties
# End of https://www.gitignore.io/api/rider,csharp,visualstudio

.DS_Store

*.bat
12 changes: 7 additions & 5 deletions Uchu.World/Handlers/Commands/CharacterCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Uchu.Core;
using Uchu.Core.Client;
using Uchu.Core.Resources;
Expand Down Expand Up @@ -86,6 +87,7 @@ public string ChangeCoin(string[] arguments, Player player)
{
if (arguments.Length != 1) return "coin <delta>";

/// We parse this as an int instead of long, due to the max long causing bugs. Currency maxes out at a long.
Copy link
Member

@MickVermeulen MickVermeulen Dec 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nitpicky but we generally only use double slash comments inline and use triple slash comments for doc strings

if (!int.TryParse(arguments[0], out var delta) || delta == default) return "Invalid <delta>";

player.Currency += delta;
Expand Down Expand Up @@ -170,7 +172,7 @@ public string Rotation(string[] arguments, Player player)
return $"{player.Transform.Rotation}";
}

[CommandHandler(Signature = "smash", Help = "Smash yourself", GameMasterLevel = GameMasterLevel.Admin)]
[CommandHandler(Signature = "smash", Help = "Smash yourself", GameMasterLevel = GameMasterLevel.Player)]
public async Task<string> Smash(string[] arguments, Player player)
{
var animation = "violent";
Expand Down Expand Up @@ -517,7 +519,7 @@ public string Stat(string[] arguments, Player player)
return $"Successfully set {arguments[0]} to {value}";
}

[CommandHandler(Signature = "pvp", Help = "Change PvP state", GameMasterLevel = GameMasterLevel.Admin)]
[CommandHandler(Signature = "pvp", Help = "Change PvP state", GameMasterLevel = GameMasterLevel.Mythran)]
public string Pvp(string[] arguments, Player player)
{
if (arguments.Length != 1) return "pvp <state(on/off)>";
Expand Down Expand Up @@ -759,7 +761,7 @@ public string AddComponent(string[] arguments, Player player)

return $"Successfully added {type.Name} to {player}";
}

[CommandHandler(Signature = "testmap", Help = "Transfer to world", GameMasterLevel = GameMasterLevel.Mythran)]
public string World(string[] arguments, Player player)
{
Expand All @@ -777,9 +779,9 @@ public string World(string[] arguments, Player player)
return $"Can't find world with ID {id}";
}

string WorldName = WorldTable.ZoneName;
var path = Path.Combine(UchuServer.Config.ResourcesConfiguration?.GameResourceFolder, Path.Combine("maps", WorldTable.ZoneName.ToLower()));

if (WorldName.EndsWith(".luz"))
if (File.Exists(path) && WorldTable.LocStatus > 0)
{
//
// We don't want to lock up the server on a world server request, as it may take time.
Expand Down
53 changes: 53 additions & 0 deletions Uchu.World/Handlers/Commands/OperatorCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Uchu.Core;
using Uchu.World.Scripting.Managed;
using Uchu.World.Social;
using Microsoft.EntityFrameworkCore;

namespace Uchu.World.Handlers.Commands
{
Expand Down Expand Up @@ -236,5 +237,57 @@ public string Target(string[] arguments, Player player)

return $"Target: {baseCombatAiComponent.Target}";
}


[CommandHandler(Signature = "execute", Help = "Execute a command as another player", GameMasterLevel = GameMasterLevel.Admin)]
public async Task<string> Execute(string[] arguments, Player executor)
Copy link
Member

@MickVermeulen MickVermeulen Dec 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate a doc string here with maybe some example usage

{
List<Player> players = new List<Player>();
if (arguments[0] == "*") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in this block doesn't adhere to the overall Uchu / C# style, we generally do:

if ()
{
    ... stuff
}
else
{
    ... other stuff
}

and

foreach ()
{
    ... stuff
}

foreach (var player in executor.Zone.Players) {
players.Add(player);
}
} else {
var player = executor.Zone.Players.FirstOrDefault(p => p.Name == arguments[0]); // This throws an error if no character is found :shrug:
if (player == default) return $"No player named {arguments[0]}";
players.Add(player);
}

await using var ctx = new UchuContext();
var character = await ctx.Characters.Include(c => c.User).FirstAsync(
c => c.Id == executor.Id
);

var _com = new List<string>(arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a odd variable name, if you meant command I would just use command here

_com.RemoveAt(0);

var message = string.Join(" ", _com);

if (!message.StartsWith('/')) {
message = "/" + message;
}

if (!SocialHandler.ClientCommands.Contains(message.Split(" ").ElementAt(0)) && message.Split(" ").ElementAt(0) != "/execute" && message.Length > 1) {
foreach (Player player in players) {
player.SendChatMessage("You feel a magical power...", PlayerChatChannel.Normal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol I like this little extra

var response = await UchuServer.HandleCommandAsync(
message, player, (GameMasterLevel)character.User.GameMasterLevel
);

if (!string.IsNullOrWhiteSpace(response)) {
//executor.SendChatMessage($"{player.Name}: {response}", PlayerChatChannel.Normal);
player.SendChatMessage(response, PlayerChatChannel.Normal);
}
}

return $"Executed \"{message}\" as {players.Count} {(players.Count == 1 ? "person" : "people")}";
}
else
{
return $"Unable to execute \"{message}\"";
}

return "Failed to execute command";
}
}
}
4 changes: 3 additions & 1 deletion Uchu.World/Handlers/SocialHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Uchu.World.Handlers
{
public class SocialHandler : HandlerGroup
{
private static string[] ClientCommands = { "/quit", "/exit", "/logoutcharacter", "/camp", "/logoutaccount", "/logout", "/say", "/s",
public static string[] ClientCommands = { "/quit", "/exit", "/logoutcharacter", "/camp", "/logoutaccount", "/logout", "/say", "/s",
"/whisper", "/w", "/tell", "/team", "/t", "/location", "/locate", "/loc", "/faq", "/faqs", "/shop", "/store", "/minigames", "/forums",
"/thumbsup", "/thumb", "/thumb", "/victory", "/backflip", "/clap", "/cringe", "/cry", "/dance", "/gasp", "/giggle", "/talk", "/salute",
"/shrug", "/sigh", "/wave", "/why", "/thanks", "/yes", "/addfriend", "/removefriend", "/addignore", "/removeignore", "/recommendedperfoptions",
Expand Down Expand Up @@ -40,6 +40,8 @@ public async Task ParseChatMessageHandler(ParseChatMessage message, Player playe
if (message.Message.StartsWith('/') && !ClientCommands.Contains(message.Message.Split(" ").ElementAt(0)))
{

//Logger.Debug($"message.Message: {message.Message}");

if (ClientCommands.Contains(message.Message.Split(" ").ElementAt(0)))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ private void WritePart4(BitWriter writer)

writer.WriteBit(IsPvP);
writer.WriteBit(IsGameMaster);
writer.Write(GameMasterLevel);

//writer.Write(GameMasterLevel); // Original code
//writer.Write((GameMasterLevel != 1 ? GameMasterLevel : 0)); // This broke the component
writer.Write(GameMasterLevel != 1 ? GameMasterLevel : (byte)0); // This casts to the correct type (u8)

writer.WriteBit(false); // ???
writer.Write<byte>(0); // ???
Expand Down
1 change: 1 addition & 0 deletions Uchu.World/Objects/GameObjects/InstancingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static GameObject InstantiateLoot(Lot lot, Player owner, GameObject sourc
public static void InstantiateCurrency(int currency, Player owner, GameObject source, Vector3 spawn)
{
if (owner is null) return;
if (currency <= 0) return;

try
{
Expand Down