Esempio n. 1
0
 public void PlayerStartInteraction(PlayerInteractionType interact)
 {
     stateModel.playerState.Value = PlayerState.InteractState;
     playerInteractBehavior[interact]();
 }
Esempio n. 2
0
        private void OnPlayerInteract(PlayerInteractPacket packet, NetPeer peer)
        {
            PlayerInteractionType interactionType = (PlayerInteractionType)packet.Type;

            if (!InstalledAddons.TryGetValue(packet.AddonId, out AddonInfo addonInfo))
            {
                Logger.Error($"Addon with id \"{packet.AddonId}\" tried to use interaction \"{interactionType}\" on player \"{packet.UserID}\" but addon is not loaded!");
                return;
            }

            NetDataReader reader = new NetDataReader(packet.Data);
            Player        p      = (packet.UserID == "SERVER CONSOLE" || packet.UserID == "GAME CONSOLE") ? Player.Get(PlayerManager.localPlayer) : Player.Get(packet.UserID);

            if (p == null)
            {
                Logger.Info($"Player not found {packet.UserID}, action: {interactionType}.");
                return;
            }

            switch (interactionType)
            {
            // Kill player
            case PlayerInteractionType.KillPlayer:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.KillPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to \"{interactionType}\" but server dont have required permission!");
                    break;
                }

                p.Kill("Force");
                break;

            // Report message
            case PlayerInteractionType.ReportMessage:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.ReportMessages))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to send \"{interactionType}\" but server dont have required permission!");
                    break;
                }

                p.SendConsoleMessage($"[REPORTING] {reader.GetString()}", "GREEN");
                break;

            // Remoteadmin message
            case PlayerInteractionType.RemoteAdminMessage:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.RemoteAdminMessages))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to send \"{interactionType}\" but server dont have required permission!");
                    break;
                }

                p.RemoteAdminMessage(reader.GetString(), true, reader.GetString());
                break;

            // Console message
            case PlayerInteractionType.GameConsoleMessage:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.GameConsoleMessages))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to send \"{interactionType}\" but server dont have required permission!");
                    break;
                }

                var message    = reader.GetString();
                var pluginName = reader.GetString();

                p.SendConsoleMessage($"{(!string.IsNullOrEmpty(pluginName) ? $"[{pluginName}] " : string.Empty)}{message}", reader.GetString());
                break;

            // Redirect
            case PlayerInteractionType.Redirect:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.RedirectPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                SendClientToServer(p, reader.GetUShort());
                break;

            // Disconnect
            case PlayerInteractionType.Disconnect:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.DisconnectPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                ServerConsole.Disconnect(p.GameObject, reader.GetString());
                break;

            // Hint
            case PlayerInteractionType.Hint:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.HintMessages))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to send \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                p.ShowHint(reader.GetString(), reader.GetFloat());
                break;

            // Send position to network
            case PlayerInteractionType.SendPosition:
                bool sendPosition = reader.GetBool();
                if (!p.SessionVariables.ContainsKey("SP"))
                {
                    p.SessionVariables.Add("SP", sendPosition);
                }
                p.SessionVariables["SP"] = sendPosition;
                break;

            // Send rotation to network
            case PlayerInteractionType.SendRotation:
                bool sendRotation = reader.GetBool();
                if (!p.SessionVariables.ContainsKey("SR"))
                {
                    p.SessionVariables.Add("SR", sendRotation);
                }
                p.SessionVariables["SR"] = sendRotation;
                break;

            // Teleport
            case PlayerInteractionType.Teleport:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.TeleportPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                p.Position = new UnityEngine.Vector3(reader.GetFloat(), reader.GetFloat(), reader.GetFloat());
                break;

            // Godmode
            case PlayerInteractionType.Godmode:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.GodmodePlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to change \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                p.IsGodModeEnabled = reader.GetBool();
                break;

            // Noclip
            case PlayerInteractionType.Noclip:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.NoclipPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to change \"{interactionType}\" player but server dont have required permission!");
                    break;
                }

                p.NoClipEnabled = reader.GetBool();
                break;

            // Clear Inv
            case PlayerInteractionType.ClearInventory:
                if (!Extensions.CheckSendPermission(AddonReceivePermissionTypes.ClearInventoryPlayer))
                {
                    Logger.Error($"Addon \"{addonInfo.AddonName}\" tried to \"{interactionType}\" but server dont have required permission!");
                    break;
                }

                p.ClearInventory();
                break;
            }
        }