• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Release] Imposter Plugin
#1
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:
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.


Attached Files
.zip   ImposterPlugin.zip (Size: 3.1 KB / Downloads: 63)
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
  Reply
#2
Nice, thanks!
  Reply
#3
i was about to code this , but @master131 did it Tongue
nice work.

*----Off Topic----*
How Fast! Big Grin
  Reply
#4
Thank you! Big Grin
  Reply
#5
I just realised I screwed up the kick message Dodgy I think it should still work though.

EDIT - Yeah, still works.
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Wink Plugin with !ban !kick and !tampban clemi555 3 3,886 11-09-2013, 09:21
Last Post: clemi555
  AntiNoScope Plugin clemi555 5 4,342 11-08-2013, 19:13
Last Post: clemi555
  [Release] Bunker Plugin 1.3 archit 68 38,162 10-30-2013, 11:59
Last Post: clacki
  Help Modifying plugin maverigh 5 5,245 10-19-2013, 10:29
Last Post: Nekochan
Shocked [Request] Switch plugin axel-le-meilleur 6 4,609 10-19-2013, 06:59
Last Post: iRoNinja
  [Release] Yurio Map Plugin Yurio 101 57,443 09-26-2013, 13:38
Last Post: First_Semyon
Brick [Release] v1.1 ChangeMap/NextMap Plugin without any configuration milchshake 23 17,345 09-23-2013, 13:18
Last Post: SgtLegend
  Help !say Plugin (like the !say from GodPlugin) Hallla 0 2,524 09-13-2013, 09:31
Last Post: Hallla
Rainbow [Release] MW3: Random Weapon Plugin V1 Nekochan 50 30,309 09-11-2013, 15:11
Last Post: EnVi Sweden Rocks
  Search Plugin Fluid Killcam N3xT_974 1 2,840 09-10-2013, 20:27
Last Post: Nekochan

Forum Jump:


Users browsing this thread: 1 Guest(s)