-
-
Notifications
You must be signed in to change notification settings - Fork 124
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 #673 from starfi5h/pr-chat
Add CLI argument -newgame-cfg and changes to chat format
- Loading branch information
Showing
12 changed files
with
301 additions
and
24 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,19 @@ | ||
using NebulaModel.DataStructures; | ||
|
||
namespace NebulaModel.Packets.Chat; | ||
|
||
public class PlayerDataCommandPacket | ||
{ | ||
public PlayerDataCommandPacket() { } | ||
|
||
public PlayerDataCommandPacket(string command, string message, PlayerData playerData = null) | ||
{ | ||
Command = command; | ||
Message = message; | ||
PlayerData = playerData; | ||
} | ||
|
||
public string Command { get; set; } | ||
public string Message { get; set; } | ||
public PlayerData PlayerData { get; set; } | ||
} |
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
62 changes: 62 additions & 0 deletions
62
NebulaNetwork/PacketProcessors/Chat/PlyaerDataCommmandProcessor.cs
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,62 @@ | ||
#region | ||
|
||
using NebulaAPI.Packets; | ||
using NebulaModel.DataStructures.Chat; | ||
using NebulaModel.Networking; | ||
using NebulaModel.Packets; | ||
using NebulaModel.Packets.Chat; | ||
using NebulaWorld; | ||
using NebulaWorld.Chat.Commands; | ||
using NebulaWorld.MonoBehaviours.Local.Chat; | ||
|
||
#endregion | ||
|
||
namespace NebulaNetwork.PacketProcessors.Chat; | ||
|
||
[RegisterPacketProcessor] | ||
internal class PlyaerDataCommmandProcessor : PacketProcessor<PlayerDataCommandPacket> | ||
{ | ||
protected override void ProcessPacket(PlayerDataCommandPacket packet, NebulaConnection conn) | ||
{ | ||
if (IsHost) | ||
{ | ||
packet.PlayerData = null; | ||
var playerSaves = SaveManager.PlayerSaves; | ||
switch (packet.Command) | ||
{ | ||
case "list": | ||
packet.Message = PlayerDataCommandHandler.GetPlayerDataListString(); | ||
break; | ||
|
||
case "load": | ||
var input = packet.Message; | ||
packet.Message = "Unable to find the target player data!"; | ||
foreach (var pair in playerSaves) | ||
{ | ||
if (input == pair.Key.Substring(0, input.Length) || input == pair.Value.Username) | ||
{ | ||
packet.Message = $"Load [{pair.Key.Substring(0, 5)}] {pair.Value.Username}"; | ||
packet.PlayerData = (NebulaModel.DataStructures.PlayerData)pair.Value; | ||
break; | ||
} | ||
} | ||
break; | ||
|
||
default: | ||
packet.Message = "Unknown command: " + packet.Command; | ||
break; | ||
} | ||
conn.SendPacket(packet); | ||
return; | ||
} | ||
|
||
if (IsClient) | ||
{ | ||
ChatManager.Instance.SendChatMessage(packet.Message, ChatMessageType.CommandOutputMessage); | ||
if (packet.PlayerData != null) | ||
{ | ||
PlayerDataCommandHandler.LoadPlayerData(packet.PlayerData); | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
#region | ||
|
||
using NebulaWorld.MonoBehaviours.Local.Chat; | ||
using NebulaModel.DataStructures.Chat; | ||
using HarmonyLib; | ||
|
||
#endregion | ||
|
||
namespace NebulaWorld.Chat.Commands; | ||
|
||
public class DevCommandHandler : IChatCommandHandler | ||
{ | ||
public void Execute(ChatWindow window, string[] parameters) | ||
{ | ||
if (parameters.Length < 1) | ||
{ | ||
throw new ChatCommandUsageException("Not enough arguments!".Translate()); | ||
} | ||
|
||
switch (parameters[0]) | ||
{ | ||
case "sandbox": | ||
{ | ||
GameMain.sandboxToolsEnabled = !GameMain.sandboxToolsEnabled; | ||
GameMain.data.gameDesc.isSandboxMode = GameMain.sandboxToolsEnabled; | ||
window.SendLocalChatMessage("SandboxTool enable: " + GameMain.sandboxToolsEnabled, ChatMessageType.CommandOutputMessage); | ||
return; | ||
} | ||
case "load-cfg": | ||
{ | ||
window.SendLocalChatMessage("Overwrite settings from nebulaGameDescSettings.cfg", ChatMessageType.CommandOutputMessage); | ||
AccessTools.Method(AccessTools.TypeByName("NebulaPatcher.NebulaPlugin"), "SetGameDescFromConfigFile").Invoke(null, [GameMain.data.gameDesc]); | ||
return; | ||
} | ||
|
||
case "self-destruct": | ||
{ | ||
GameMain.mainPlayer.Kill(); | ||
return; | ||
} | ||
|
||
default: | ||
window.SendLocalChatMessage("Unknown command: " + parameters[0], ChatMessageType.CommandOutputMessage); | ||
return; | ||
} | ||
} | ||
|
||
public string GetDescription() | ||
{ | ||
return "Developer/Sandbox tool commands".Translate(); | ||
} | ||
|
||
public string[] GetUsage() | ||
{ | ||
return ["sandbox", "load-cfg", "self-destruct"]; | ||
} | ||
} |
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
Oops, something went wrong.