using UnityEngine;
using System;
namespace MSCO
{
///
/// Alle MSCO-Befehle an einer Stelle - genutzt von der eigenen F7-Konsole (ohne "mp" davor)
/// (früher auch aus der MSCLoader-Konsole - MSCO läuft jetzt ohne MSCLoader).
///
public static class Commands
{
public const string Help =
"connect - join a dedicated server\n" +
"switch - quickly switch to a favorite server (also /switch in chat)\n" +
"fav - list your favorite servers\n" +
"fav add [host:port] - add a favorite (without address: the server you are on)\n" +
"fav remove - remove a favorite\n" +
"disconnect - leave the server / game\n" +
"host [port] / join [port] - direct LAN game (no Steam)\n" +
"save - save the game (host / singleplayer)\n" +
"bind [action key] - show / change keys (passenger, console, chat)\n" +
"ping [on|off] - show your ping to the server (toggle)\n" +
"fps [on|off] - show the frames per second (toggle)\n" +
"/admin - admin menu (kick / ban / teleport / cheats)\n" +
"vehicles | rig - debug info about vehicles / player models\n" +
"model [game|classic] - other players as MSC characters or the MSCO figure\n" +
"vars - synced vehicle values, e.g. vars oil (debug)\n" +
"debug - toggle sync debug output\n" +
"clear - clear this console";
static void Favorite(MultiplayerManager mp, string[] args, Action print)
{
string sub = args.Length > 1 ? args[1].ToLower() : "list";
if (sub == "list")
{
if (Favorites.All.Count == 0) { print("No favorites yet - open a server in the browser and press FAVORITE, or: fav add "); return; }
foreach (Favorites.Favorite f in Favorites.All)
print(" " + f.Nickname + " -> " + f.Address + (string.IsNullOrEmpty(f.ServerName) ? "" : " (" + f.ServerName + ")"));
print("switch to join one");
return;
}
if (sub == "add" || sub == "set")
{
if (args.Length < 3) { print("fav add [host:port]"); return; }
string host = mp.CurrentServerHost, name = mp.CurrentServerName;
int port = mp.CurrentServerPort;
if (args.Length > 3 && !ServerBrowser.TryParseAddress(args[3], out host, out port)) { print("Invalid address: " + args[3]); return; }
if (host == null) { print("You are not on a server - use: fav add "); return; }
string error = Favorites.Set(args[2], host, port, name);
print(error ?? "Favorite '" + Favorites.CleanNickname(args[2]) + "' saved (" + host + ":" + port + ")");
return;
}
if (sub == "remove" || sub == "del" || sub == "delete")
{
Favorites.Favorite f = args.Length > 2 ? Favorites.Find(args[2]) : null;
print(f != null && Favorites.Remove(f) ? "Favorite '" + f.Nickname + "' removed" : "No such favorite");
return;
}
print("fav | fav add [host:port] | fav remove ");
}
public static void Execute(string[] args, Action print)
{
var mp = MultiplayerManager.Instance;
if (mp == null) { print("Not ready yet"); return; }
if (args.Length == 0) { print(Help); return; }
int port = MultiplayerManager.DefaultPort;
switch (args[0].ToLower())
{
case "help":
case "?":
print(Help);
break;
case "host":
if (args.Length > 1) int.TryParse(args[1], out port);
mp.Host(port);
break;
case "join":
if (args.Length < 2) { print("join [port]"); return; }
if (args.Length > 2) int.TryParse(args[2], out port);
mp.Join(args[1], port);
break;
case "stop":
case "disconnect":
case "quit":
mp.Disconnect();
print("Disconnected.");
break;
case "connect":
{
string host;
int serverPort;
if (args.Length < 2 || !ServerBrowser.TryParseAddress(args[1], out host, out serverPort))
{
print("connect ");
return;
}
mp.JoinServer(host, serverPort);
break;
}
case "switch":
case "sw":
print(mp.SwitchServer(args.Length > 1 ? args[1] : ""));
break;
case "fav":
case "favs":
case "favorites":
Favorite(mp, args, print);
break;
case "save":
mp.SaveGame();
break;
case "ping":
// "ping" schaltet die Anzeige um, "ping on/off" setzt sie
if (args.Length > 1) mp.ShowPing = args[1].ToLower() == "on" || args[1] == "1";
else mp.ShowPing = !mp.ShowPing;
print("Ping: " + mp.PingText + " (display " + (mp.ShowPing ? "on" : "off") + ")");
break;
case "bind":
{
// Tasten ändern: "bind" zeigt alle, "bind passenger O" setzt eine (früher MSCLoader-Einstellungen)
if (args.Length < 3)
{
foreach (KeyBinding k in MSCO.Keys) print(" " + k.Id.PadRight(10) + " " + k.Key + " (" + k.Description + ", default " + k.Default + ")");
print("Change: bind <" + string.Join("|", System.Array.ConvertAll(MSCO.Keys, k => k.Id)) + "> e.g. bind passenger O");
break;
}
KeyBinding target = System.Array.Find(MSCO.Keys, k => k.Id.Equals(args[1], System.StringComparison.OrdinalIgnoreCase));
KeyCode key;
if (target == null) print("Unknown action " + args[1] + " - see 'bind'");
else if (!KeyBinding.TryParse(args[2], out key)) print("Unknown key " + args[2] + " (Unity key names, e.g. O, F6, Keypad5, Mouse3)");
else { target.Key = key; print(target.Description + ": " + key); }
break;
}
case "fps":
// "fps" schaltet die Anzeige um, "fps on/off" setzt sie
if (args.Length > 1) mp.ShowFps = args[1].ToLower() == "on" || args[1] == "1";
else mp.ShowFps = !mp.ShowFps;
print("FPS: " + mp.FpsText + " (display " + (mp.ShowFps ? "on" : "off") + ")");
break;
case "admin":
case "/admin":
mp.OpenAdminMenu();
break;
case "rig":
foreach (string line in mp.DescribeRigs()) print(line);
break;
case "model":
// Mitspieler als echte MSC-Menschen ("game") oder als MSCO-Figur ("classic")
if (args.Length > 1) RemotePlayer.UseGameModels = args[1].ToLower() != "classic";
else RemotePlayer.UseGameModels = !RemotePlayer.UseGameModels;
mp.RebuildAvatars();
print("Player models: " + (RemotePlayer.UseGameModels ? "MSC characters (model classic = MSCO figure)" : "MSCO figure (model game = MSC characters)"));
break;
case "vehicles":
foreach (string line in mp.DescribeVehicles()) print(line);
break;
case "vars":
// Diagnose: welche Fahrzeugwerte synchronisiert werden (z.B. "vars oil")
foreach (string line in mp.DescribeVehicleValues(args.Length > 1 ? args[1] : "")) print(line);
break;
case "debug":
FsmSync.Debug = !FsmSync.Debug;
print("Sync debug output " + (FsmSync.Debug ? "ON" : "OFF"));
break;
default:
print("Unknown command '" + args[0] + "' - type 'help'");
break;
}
}
}
}