I present to you the awful and possibly badly coded Imposter Plugin as requested by @pollarpart. Hahaha, I'm kidding. :p What it basically does is stops anyone from joining the game if their name is in the database and their XUIDs don't match hence the 'imposter' term used.
Source:
Usage:
!setreal <player name> - Set's the player in the current game as the 'real' person.
!setreal <player name> <xuid> - Adds the player and xuid to the list, the player doesn't have to be in the server.
Requirements:
Permissions Plugin by Pozzuh
Make sure to add the !setreal command to the allowed commands.
Source:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Addon;
namespace ImposterPlugin
{
public class ImposterPlugin : CPlugin
{
Dictionary<string, string> _realPlayers = new Dictionary<string, string>();
#region Permission/Setting Functions
string CheckSetting(string key, string value)
{
if (string.IsNullOrEmpty(GetServerCFG("ImposterPlugin", key, "")))
{
SetServerCFG("ImposterPlugin", key, value);
return value;
}
return GetServerCFG("ImposterPlugin", key, "");
}
List<string> GetCommandsAllowedInGroup(string groupname)
{
List<string> group = new List<string>();
string group_string = GetServerCFG("Permission", groupname + "_commands", " ");
if (group_string != " ")
foreach (string cmd in group_string.Split(','))
group.Add(cmd);
return group;
}
List<string> GetUsersInGroup(string groupname)
{
List<string> group = new List<string>();
string group_string = GetServerCFG("Permission", groupname + "_xuids", " ");
if (group_string != " ")
foreach (string xuid in group_string.Split(','))
group.Add(xuid);
return group;
}
bool CommandAllowedForPlayer(string XUID, string command)
{
foreach (string usergroup in GetServerCFG("Permission", "Usergroups", "").Split(','))
if ((GetCommandsAllowedInGroup(usergroup).Contains(command) || GetCommandsAllowedInGroup(usergroup).Contains("*ALL*")) && GetUsersInGroup(usergroup).Contains(XUID))
return true;
return false;
}
#endregion
public override void OnServerLoad()
{
if (!string.IsNullOrEmpty(CheckSetting("RealList", string.Empty)))
foreach (var pair in CheckSetting("RealList", string.Empty).Split(','))
_realPlayers.Add(pair.Split(';')[0], pair.Split(';')[1]);
ServerPrint("Imposter Plugin v1 has been loaded!");
}
public override void OnPlayerConnect(ServerClient Client)
{
if (_realPlayers.ContainsKey(Client.Name) && _realPlayers[Client.Name] != Client.XUID)
ServerCommand(string.Format("kickclient {0} \"Imposter detected!", Client.ClientNum));
}
public override ChatType OnSay(string Message, ServerClient Client)
{
if (Message.StartsWith("!setreal") && CommandAllowedForPlayer(Client.XUID, "!setreal"))
{
string[] parts = Message.Split(' ');
// Accept 1 or 2 parameters (including the !setreal itself)
if(parts.Length == 2 || parts.Length == 3)
{
foreach(ServerClient client in GetClients())
{
if(client.Name == parts[1])
{
// Take the XUID from the 2nd parameter if possible, otherwise just
// grab the XUID from the current player in game with the matching name.
string xuid = parts.Length == 3 ? parts[2] : client.XUID;
if (_realPlayers.ContainsKey(parts[1]))
_realPlayers[parts[1]] = xuid;
else
_realPlayers.Add(parts[1], xuid);
string newSetting = string.Empty;
foreach(var kvp in _realPlayers)
{
if(!string.IsNullOrEmpty(newSetting))
newSetting += ',';
newSetting += kvp.Key + ";" + kvp.Value;
}
// Update settings.
SetServerCFG("ImposterPlugin", "RealList", newSetting);
return ChatType.ChatNone;
}
}
TellClient(Client.ClientNum, string.Format("Could not find ^3{0} ^7in the game!", parts[1]), true);
}
}
return ChatType.ChatContinue;
}
}
}
Usage:
!setreal <player name> - Set's the player in the current game as the 'real' person.
!setreal <player name> <xuid> - Adds the player and xuid to the list, the player doesn't have to be in the server.
Requirements:
Permissions Plugin by Pozzuh
Make sure to add the !setreal command to the allowed commands.
A casual conversation between barata and I about Nukem.