|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 |
| -using System.Text; |
5 |
| -using Archipelago.MultiClient.Net; |
6 |
| -using Archipelago.MultiClient.Net.MessageLog.Messages; |
7 |
| -using Archipelago.MultiClient.Net.Packets; |
| 1 | +using Archipelago.MultiClient.Net.Packets; |
8 | 2 | using ModCore;
|
9 |
| -using UnityEngine; |
10 | 3 |
|
11 | 4 | namespace ArchipelagoRandomizer
|
12 | 5 | {
|
13 |
| - |
14 |
| - public class APCommand |
15 |
| - { |
16 |
| - [DebugMenuCommand(commandName: "archipelago", commandAliases: ["ap"], caseSensitive:true)] |
17 |
| - private void SendAPCommand(string[] args) |
18 |
| - { |
19 |
| - if (args.Length == 0) |
20 |
| - { |
21 |
| - DebugMenuManager.LogToConsole("USAGE:\n" + |
22 |
| - " ap /connect {server:port} {slot} {password}: Connect to an Archipelago server\n" + |
23 |
| - " ap !hint {item}: Hint the location of an item\n" + |
24 |
| - " ap !release: Release all items remaining in your world to other worlds (if you have permission)\n" + |
25 |
| - " ap !collect: Receive all items that belong to your world (if you have permission)\n" + |
26 |
| - "You can also simply type to chat with other players.", DebugMenuManager.TextColor.Error); |
27 |
| - return; |
28 |
| - } |
29 |
| - if (args[0] == "/connect") |
30 |
| - { |
31 |
| - if (args.Length < 3) |
32 |
| - { |
33 |
| - DebugMenuManager.LogToConsole("USAGE:\n" + |
34 |
| - " ap /connect {server:port} {slot} {password (if needed)}\n" + |
35 |
| - "Examples:" + |
36 |
| - "ap /connect localhost:38281 PlayerIttle\n" + |
37 |
| - "ap /connect archipelago.gg:12345 PlayerIttle mYPassWord", DebugMenuManager.TextColor.Error); |
38 |
| - return; |
39 |
| - } |
40 |
| - string server = args[1]; |
41 |
| - string slot = args[2]; |
42 |
| - string password = ""; |
43 |
| - if (args.Length >= 4) password = args[3]; |
44 |
| - if (Archipelago.TryCreateSession(server, slot, password, out string message)) |
45 |
| - { |
46 |
| - DebugMenuManager.LogToConsole(message, DebugMenuManager.TextColor.Success); |
47 |
| - } |
48 |
| - else |
49 |
| - { |
50 |
| - DebugMenuManager.LogToConsole(message, DebugMenuManager.TextColor.Error); |
51 |
| - } |
52 | 6 |
|
53 |
| - return; |
54 |
| - } |
55 |
| - |
56 |
| - if (Archipelago.session == null) |
57 |
| - { |
58 |
| - DebugMenuManager.LogToConsole("No session active. Please connect with 'ap /connect' first.", DebugMenuManager.TextColor.Error); |
59 |
| - return; |
60 |
| - } |
| 7 | + public class APCommand |
| 8 | + { |
| 9 | + private static APCommand instance; |
| 10 | + public static APCommand Instance { get { return instance; } } |
61 | 11 |
|
62 |
| - string combinedArgs = string.Join(" ", args).TrimEnd(); |
| 12 | + public APCommand() |
| 13 | + { |
| 14 | + instance = this; |
| 15 | + DebugMenuManager.AddCommands(this); |
| 16 | + } |
63 | 17 |
|
64 |
| - if (combinedArgs == "") return; |
| 18 | + [DebugMenuCommand(commandName: "archipelago", commandAliases: ["ap"], caseSensitive: true)] |
| 19 | + private void SendAPCommand(string[] args) |
| 20 | + { |
| 21 | + if (args.Length == 0) |
| 22 | + { |
| 23 | + DebugMenuManager.LogToConsole("USAGE:\n" + |
| 24 | + " ap /connect {server:port} {slot} {password}: Connect to an ArchipelagoHandler server\n" + |
| 25 | + " ap !hint {item}: Hint the location of an item\n" + |
| 26 | + " ap !release: Release all items remaining in your world to other worlds (if you have permission)\n" + |
| 27 | + " ap !collect: Receive all items that belong to your world (if you have permission)\n" + |
| 28 | + "You can also simply type to chat with other players.", DebugMenuManager.TextColor.Error); |
| 29 | + return; |
| 30 | + } |
| 31 | + if (args[0] == "/connect") |
| 32 | + { |
| 33 | + if (args.Length < 3) |
| 34 | + { |
| 35 | + DebugMenuManager.LogToConsole("USAGE:\n" + |
| 36 | + " ap /connect {server:port} {slot} {password (if needed)}\n" + |
| 37 | + "Examples:" + |
| 38 | + "ap /connect localhost:38281 PlayerIttle\n" + |
| 39 | + "ap /connect archipelago.gg:12345 PlayerIttle mYPassWord", DebugMenuManager.TextColor.Error); |
| 40 | + return; |
| 41 | + } |
| 42 | + string server = args[1]; |
| 43 | + string slot = args[2]; |
| 44 | + string password = ""; |
| 45 | + if (args.Length >= 4) password = args[3]; |
| 46 | + if (APHandler.Instance.TryCreateSession(server, slot, password, out string message)) |
| 47 | + { |
| 48 | + DebugMenuManager.LogToConsole(message, DebugMenuManager.TextColor.Success); |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + DebugMenuManager.LogToConsole(message, DebugMenuManager.TextColor.Error); |
| 53 | + } |
65 | 54 |
|
66 |
| - Archipelago.session.Socket.SendPacket(new SayPacket() { Text = combinedArgs }); |
67 |
| - } |
68 |
| - |
69 |
| - } |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + if (APHandler.Session == null) |
| 59 | + { |
| 60 | + DebugMenuManager.LogToConsole("No session active. Please connect with 'ap /connect' first.", DebugMenuManager.TextColor.Error); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + string combinedArgs = string.Join(" ", args).TrimEnd(); |
| 65 | + |
| 66 | + if (combinedArgs == "") return; |
| 67 | + |
| 68 | + APHandler.Session.Socket.SendPacket(new SayPacket() { Text = combinedArgs }); |
| 69 | + } |
| 70 | + |
| 71 | + } |
70 | 72 | }
|
0 commit comments