public override void InvokeServer(Dictionary <string, string> contents) { if (!int.TryParse(contents["Id"], out int idx)) { SandboxMain.Log($"Invalid ID \"{contents["Id"]}\" Replicated", true); return; } if (!int.TryParse(contents["Amount"], out int amt)) { SandboxMain.Log($"Invalid amount \"{contents["Amount"]}\" Replicated, overriding to 1", true); amt = 1; } if (!DataUtils.ReadVector3FromDictionary("Location", ref contents, out Vector3 hit)) { SandboxMain.Log( $"Invalid location \"[{contents["Location.x"]}, {contents["Location.y"]}, {contents["Location.z"]}] Replicated", true); return; } for (int i = 0; i < amt; i++) { Vector3 randomDirection = new Vector3(Random.value, Random.value, Random.value); PickupDropletController.CreatePickupDroplet(MakeIndex(idx), hit + Vector3.up * 1.5f, Vector3.up * 20f + randomDirection * 5f); } }
public static bool RayTrace(out RaycastHit hit) { Camera camera = Camera.main; if (camera == null) { SandboxMain.Log("Unable to find camera reference.", true); hit = new RaycastHit(); return(false); } Transform transform = camera.transform; Ray ray = new Ray { origin = transform.position, direction = transform.forward }; if (Physics.Raycast(ray, out hit)) { return(true); } SandboxMain.Log("Unable to find trace location.", true); return(false); }
public override void InvokeServer(Dictionary <string, string> contents) { string username = contents["Target"]; string idStr = contents["Id"]; string amtStr = contents["Amount"]; if (!int.TryParse(amtStr, out int amt)) { amt = 1; } NetworkUser user = UnityUtils.GetNetworkUserWithName(username); if (user == null) { SandboxMain.Log($"Unable to find user with name {username}"); return; } if (Enum.TryParse(idStr, true, out ItemIndex item)) { user.GetCurrentBody().inventory.GiveItem(item, amt); } else if (Enum.TryParse(idStr, true, out EquipmentIndex _)) { user.GetCurrentBody().inventory.GiveEquipmentString(idStr); } }
protected override PreparedResult Prepare(Dictionary <string, object> conVars, ref Dictionary <string, string> packetContents) { foreach (Command cmd in SandboxMain.CmdHandler.GetCommands()) { SandboxMain.ToHud(" -- " + cmd.Key()); } return(PreparedResult.Stop); }
// ReSharper disable once MemberCanBePrivate.Global public static PlayerCharacterMasterController GetPlayerController( Predicate <PlayerCharacterMasterController> filter) { foreach (PlayerCharacterMasterController ctrlr in PlayerCharacterMasterController.instances) { SandboxMain.Debug($"Player controller: {ctrlr.GetDisplayName()}, isLocal: {ctrlr.isLocalPlayer}"); if (filter(ctrlr)) { return(ctrlr); } } return(null); }
// ReSharper disable once MemberCanBeMadeStatic.Global public void Replicate(CommandPacket pkt) { NetworkClient client = NetworkManager.singleton.client; if (client == null) { SandboxMain.Log("NetworkManager.singleton.client is null", true); return; } if (!client.Send(CommandPacketType, pkt)) { SandboxMain.Log($"Failed to replicate command {pkt.CmdKey}", true); } }
protected override PreparedResult Prepare(Dictionary <string, object> conVars, ref Dictionary <string, string> packetContents) { if (!UnityUtils.RayTrace(out RaycastHit hit)) { return(PreparedResult.Stop); } string id = conVars["Id"].ToString(); string[] nearbyNames = DataUtils.SelectEnum(id, out T idx, 3, false, GetDefault()); if (AreEqual(idx, GetDefault())) { SandboxMain.ToHud("Unable to find ID: " + id); // ReSharper disable once InvertIf if (nearbyNames.Length > 0) { SandboxMain.ToHud("Did you mean:"); foreach (string t in nearbyNames) { SandboxMain.ToHud(" " + t); } } return(PreparedResult.Stop); } string amtStr = conVars["Amount"].ToString(); if (!int.TryParse(amtStr, out int amt)) { amt = 1; } packetContents.Add("Id", ToInteger(idx).ToString()); packetContents.Add("Amount", amt.ToString()); DataUtils.WriteVector3ToDictionary("Location", hit.point, ref packetContents); return(PreparedResult.Replicate); }
public override void InvokeServer(Dictionary <string, string> contents) { string spawnCard = contents["SpawnCard"]; if (!DataUtils.ReadVector3FromDictionary("Location", ref contents, out Vector3 hit)) { SandboxMain.Log( $"Invalid location \"[{contents["Location.x"]}, {contents["Location.y"]}, {contents["Location.z"]}] Replicated", true); return; } SpawnCard card = Resources.Load <SpawnCard>("SpawnCards/" + spawnCard); if (card == null) { SandboxMain.Log($"Unable to load a spawnCard called \"{spawnCard}\"", true); return; } card.DoSpawn(hit, Quaternion.identity); }
public void Invoke(IEnumerable <string> arguments) { Dictionary <string, object> conVars = new Dictionary <string, object>(); ParseArguments(arguments, ref conVars); CommandPacket pkt = new CommandPacket(); if (Prepare(conVars, ref pkt.Contents) == PreparedResult.Stop) { return; } if (NetworkServer.active) { SandboxMain.Log($"Invoking command \"{Key()}\" on server"); InvokeServer(pkt.Contents); } else { SandboxMain.NetHandler.Replicate(pkt); } }
public void StartServer() { SandboxMain.Log("NetworkCommandListener starting"); NetworkServer.RegisterHandler(CommandPacketType, HandlePacket); SandboxMain.Log("NetworkCommandListener started"); }
// ReSharper disable once MemberCanBeMadeStatic.Global public void StopServer() { SandboxMain.Log("NetworkCommandListener stopping"); NetworkServer.UnregisterHandler(CommandPacketType); SandboxMain.Log("NetworkCommandListener stopped"); }