C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using System.Collections.Generic;
using System;
namespace Oxide.Plugins
{
[Info("Force Joiner", "Zeeuss", "0.1.0")]
[Description("Simple command to force join players to other server")]
public class ForceJoiner : RustPlugin
{
#region Init & Fields
private const string permUse = "forcejoiner.use";
private const string permBypass = "forcejoiner.bypass";
private const string permUseAll = "forcejoiner.useall";
void Init()
{
permission.RegisterPermission(permUse, this);
permission.RegisterPermission(permBypass, this);
permission.RegisterPermission(permUseAll, this);
AddCovalenceCommand("fjoin", "forceJoinCmd", permUse);
AddCovalenceCommand("fjoinall", "forceJoinAllCmd", permUseAll);
}
#endregion
#region FJoin command
void forceJoinCmd(IPlayer player, string command, string[] args)
{
if(args.Length < 2)
{
player.Message(lang.GetMessage("Syntax fjoin", this, player.Id));
return;
}
BasePlayer target = BasePlayer.Find(args[0]);
if(target == null)
{
player.Message(lang.GetMessage("No Player", this, null));
return;
}
if(permission.UserHasPermission(target.UserIDString, permBypass))
{
player.Message(String.Format(lang.GetMessage("Bypass", this, player.Id), target.displayName));
return;
}
if (!args[1].Contains(':'))
{
player.Message(lang.GetMessage("Syntax fjoin", this, player.Id));
return;
}
string[] split = args[1].Split(':', 2);
string ip = split[0];
string port = split[1];
if(String.IsNullOrWhiteSpace(ip) || String.IsNullOrWhiteSpace(port))
{
player.Message(lang.GetMessage("Syntax fjoin", this, player.Id));
return;
}
ConsoleNetwork.SendClientCommandImmediate(target.Connection, "nexus.redirect", ip, port);
ConnectionAuth.Reject(target.Connection, "Redirected");
PlatformService.Instance.EndPlayerSession(target.userID);
player.Message(String.Format(lang.GetMessage("Fjoin", this, player.Id), target.displayName, ip, port));
}
#endregion
#region FJoinAll command
void forceJoinAllCmd(IPlayer player, string command, string[] args)
{
if (args.Length < 1)
{
player.Message(lang.GetMessage("Syntax fjoinall", this, player.Id));
return;
}
if (!args[0].Contains(':'))
{
player.Message(lang.GetMessage("Syntax fjoin", this, player.Id));
return;
}
string[] split = args[0].Split(':', 2);
string ip = split[0];
string port = split[1];
int i = 0;
foreach(BasePlayer target in BasePlayer.activePlayerList)
{
if (permission.UserHasPermission(target.UserIDString, permBypass))
continue;
ConsoleNetwork.SendClientCommandImmediate(target.Connection, "nexus.redirect", ip, port);
ConnectionAuth.Reject(target.Connection, "Redirected");
PlatformService.Instance.EndPlayerSession(target.userID);
i++;
}
player.Message(String.Format(lang.GetMessage("Fjoinall", this, player.Id), i, ip, port));
}
#endregion
#region Localization
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Syntax fjoin"] = "Syntax: /fjoin (player) (ip:port)",
["Syntax fjoinall"] = "Syntax: /fjoinall (ip:port)",
["No Player"] = "Couldn't find the target player",
["Fjoin"] = "Forcing {0} to {1}:{2}",
["Fjoinall"] = "Forcing everyone({0} players) to {1}:{2}",
["Bypass"] = "{0} cannot be forced to other server.",
}, this);
}
#endregion
}
}