Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Collections;
- using System.Net;
- using System.Web;
- using System.Data;
- using System.Threading;
- using System.Security;
- using System.Timers;
- using System.Diagnostics;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using PRoCon.Core;
- using PRoCon.Core.Plugin;
- using PRoCon.Core.Plugin.Commands;
- using PRoCon.Core.Players;
- using PRoCon.Core.Players.Items;
- using PRoCon.Core.Battlemap;
- using PRoCon.Core.Maps;
- namespace PRoConEvents
- {
- using EventType = PRoCon.Core.Events.EventType;
- using CapturableEvent = PRoCon.Core.Events.CapturableEvents;
- public class VoteChange : PRoConPluginAPI, IPRoConPluginInterface
- {
- double votePercentage = 0.66;
- int playerCount = 0;
- string cmdthing = "";
- List<string[]> Votes = new List<string[]>();
- List<string[]> teamVotes = new List<string[]>();
- string[,] Maps = new string[,] { {"Zavod 311", "MP_Abandoned"},
- {"Lancang Dam", "MP_Damage"},
- {"Flood Zone", "MP_Flooded"},
- {"Golmud Railway", "MP_Journey"},
- {"Paracel Storm", "MP_Naval"},
- {"Operation Locker", "MP_Prison"},
- {"Hainan Resort", "MP_Resort"},
- {"Siege of Shanghai", "MP_Siege"},
- {"Rogue Transmission", "MP_TheDish"},
- {"Dawnbreaker", "MP_Tremors"},
- {"Silk Road", "XP1_001"},
- {"Altai Range", "XP1_002"},
- {"Guilin Peaks", "XP1_003"},
- {"Dragon Pass", "XP1_004"},
- {"Caspian Border", "XP0_Caspian"},
- {"Operation Firestorm", "XP0_Firestorm"},
- {"Operation Metro", "XP0_Metro"},
- {"Gulf of Oman", "XP0_Oman"},
- {"Lost Islands", "XP2_001"},
- {"Nansha Strike", "XP2_002"},
- {"Wavebreaker", "XP2_003"},
- {"Operation Mortar", "XP2_004"},
- {"Propaganda", "XP3_Prpganda"},
- {"Sunken Dragon", "XP3_WtrFront"},
- {"Pearl Market", "XP3_MarketPl"},
- {"Lumphini Garden", "XP3_UrbanGdn"},
- {"Operation Whiteout", "XP4_Arctic"},
- {"Hammerhead", "XP4_SubBase"},
- {"Hangar 21", "XP4_Titan"},
- {"Giants of Karelia", "XP4_Wlkrftry"}
- };
- public VoteChange()
- {
- }
- public void ServerCommand(params String[] args)
- {
- List<String> list = new List<String>();
- list.Add("procon.protected.send");
- list.AddRange(args);
- this.ExecuteCommand(list.ToArray());
- }
- bool isVoteCorrect(string vote, string speaker)
- {
- bool alreadyFound = false;
- for(int i = 0; i < 30; i++)
- {
- bool contains = Maps[i,0].ToLower().Contains(vote);
- if(contains)
- {
- if(!alreadyFound)
- {
- alreadyFound = true;
- }
- else
- {
- ServerCommand("admin.say", "Found more than one map. Please be more specific!", "player", speaker);
- return false;
- }
- }
- }
- if(alreadyFound)
- {
- return true;
- }
- return false;
- }
- string[] getMap(string vote)
- {
- string[] mapInfo = new string[2];
- for(int i = 0; i < Maps.Length; i++)
- {
- bool contains = Maps[i,0].ToLower().Contains(vote);
- if(contains)
- {
- mapInfo[0] = Maps[i,0];
- mapInfo[1] = Maps[i,1];
- return mapInfo;
- }
- }
- return mapInfo;
- }
- float countVotes(string map)
- {
- float votes = 0;
- foreach(string[] vote in Votes)
- {
- if(vote[1] == map)
- {
- //ServerCommand("admin.say", "Vote found", "all");
- votes += 1;
- }
- }
- return votes;
- }
- int hasVoted(string speaker)
- {
- int index = 0;
- foreach(string[] vote in Votes)
- {
- if(vote[0] == speaker)
- return index;
- index++;
- }
- return -1;
- }
- bool teamVoteIsCorrect(string arg1, string arg2)
- {
- if(!arg1.Equals("US", StringComparison.InvariantCultureIgnoreCase) && !arg1.Equals("CH", StringComparison.InvariantCultureIgnoreCase) && !arg1.Equals("RU", StringComparison.InvariantCultureIgnoreCase))
- return false;
- if(!arg2.Equals("US", StringComparison.InvariantCultureIgnoreCase) && !arg2.Equals("CH", StringComparison.InvariantCultureIgnoreCase) && !arg2.Equals("RU", StringComparison.InvariantCultureIgnoreCase))
- return false;
- return true;
- }
- int teamVoteStringToID(string team)
- {
- if(team.Equals("us", StringComparison.InvariantCultureIgnoreCase))
- return 0;
- if(team.Equals("ru", StringComparison.InvariantCultureIgnoreCase))
- return 1;
- if(team.Equals("ch", StringComparison.InvariantCultureIgnoreCase))
- return 2;
- else
- return -1;
- }
- int countTeamVotes(string team1, string team2)
- {
- int votes = 0;
- foreach(string[] vote in teamVotes)
- {
- if(vote[1] == team1 && vote[2] == team2)
- votes++;
- }
- return votes;
- }
- void parseMessage(string speaker, string message)
- {
- string[] arguments = message.Split(' ');
- if (arguments[0].Equals("!votechange", StringComparison.InvariantCultureIgnoreCase))
- {
- string vote = "";
- for(int i=1; i<arguments.Length; i++)
- {
- if(i == arguments.Length-1)
- vote += arguments[i].ToLower();
- else
- vote += arguments[i].ToLower() + " ";
- }
- if (isVoteCorrect(vote, speaker))
- {
- string[] Map = getMap(vote);
- int voteIndex = hasVoted(speaker);
- if(voteIndex < 0)
- {
- ServerCommand("admin.say", speaker + " voted for " + Map[0], "all");
- string[] voteToAdd = new string[] { speaker, Map[0] };
- Votes.Add(voteToAdd);
- }
- else
- {
- ServerCommand("admin.say", speaker + " changed vote to " + Map[0], "all");
- Votes[voteIndex][1] = Map[0];
- }
- float voteCount = countVotes(Map[0]);
- float players = (float)playerCount;
- //ServerCommand("admin.say", "Votecount: " + voteCount.ToString() + " Players: " + players.ToString(), "all");
- double ratio = voteCount/players;
- if (ratio >= votePercentage)
- {
- Votes.Clear();
- ServerCommand("mapList.clear");
- ServerCommand("admin.say", (Math.Round(votePercentage,2)*100).ToString() + "% exceeded. Changing map to " + Map[0] + " in 10 seconds", "all");
- this.ExecuteCommand("procon.protected.tasks.add", "2", "1", "1", "procon.protected.send", "mapList.add", Map[1], "ConquestLarge0", "1");
- this.ExecuteCommand("procon.protected.tasks.add", "5", "1", "1", "procon.protected.send", "mapList.save");
- this.ExecuteCommand("procon.protected.tasks.add", "10", "1", "1", "procon.protected.send", "mapList.runNextRound");
- }
- else
- ServerCommand("admin.say", Math.Round((float)(ratio*100), 2).ToString() + "% of the players have voted for " + Map[0], "all");
- }
- else
- ServerCommand("admin.say", "No maps corresponding to your vote were found", "player", speaker);
- }
- else if (arguments[0].Equals("!revote", StringComparison.InvariantCultureIgnoreCase))
- {
- foreach (string[] vote in Votes)
- {
- if (vote[0] == speaker)
- {
- Votes.Remove(vote);
- ServerCommand("admin.say", "Vote removed", "player", speaker);
- return;
- }
- }
- ServerCommand("admin.say", "You haven't voted for a map", "player", speaker);
- }
- else if(arguments[0].Equals("!voteteams", StringComparison.InvariantCultureIgnoreCase))
- {
- if(arguments.Length == 3)
- {
- if(teamVoteIsCorrect(arguments[1].ToLower(), arguments[2].ToLower()))
- {
- string[] voteToAdd = new string[] {speaker, arguments[1].ToLower(), arguments[2].ToLower()};
- teamVotes.Add(voteToAdd);
- float voteCount = countTeamVotes(arguments[1].ToLower(), arguments[2].ToLower());
- float players = (float)playerCount;
- double ratio = voteCount/players;
- if (ratio >= votePercentage)
- {
- teamVotes.Clear();
- ServerCommand("admin.say", (Math.Round(votePercentage,2)*100).ToString() + "% exceeded. Changing teams to " + arguments[1].ToUpper() + " vs. " + arguments[2].ToUpper() + " in 10 seconds", "all");
- this.ExecuteCommand("procon.protected.tasks.add", "2", "1", "1", "procon.protected.send", "vars.teamFactionOverride", "1", teamVoteStringToID(arguments[1]).ToString());
- this.ExecuteCommand("procon.protected.tasks.add", "2", "1", "1", "procon.protected.send", "vars.teamFactionOverride", "2", teamVoteStringToID(arguments[2]).ToString());
- this.ExecuteCommand("procon.protected.tasks.add", "10", "1", "1", "procon.protected.send", "mapList.restartRound");
- }
- else
- ServerCommand("admin.say", Math.Round((float)(ratio*100), 2).ToString() + "% of the players have voted for " + arguments[1].ToUpper() + " vs. " + arguments[2].ToUpper(), "all");
- }
- else
- ServerCommand("admin.say", "Your vote has invalid arguments. Use US, CH or RU.", "player", speaker);
- }
- else
- ServerCommand("admin.say", "Not enough arguments. !voteTeams <team1> <team2>", "player", speaker);
- }
- else if(arguments[0].Equals("!help", StringComparison.InvariantCultureIgnoreCase))
- {
- ServerCommand("admin.say", "!voteChange <map>", "player", speaker);
- ServerCommand("admin.say", "!voteTeams <Team1> <Team2>", "player", speaker);
- ServerCommand("admin.say", "Votes need " + (Math.Round(votePercentage,2)*100).ToString() + "% to pass.", "player", speaker);
- }
- }
- public void LogWrite(String msg)
- {
- this.ExecuteCommand("procon.protected.pluginconsole.write", msg);
- }
- public String GetPluginName()
- {
- return "Vote Change!";
- }
- public String GetPluginVersion()
- {
- return "1.3.0.1";
- }
- public String GetPluginAuthor()
- {
- return "Hattiwatti";
- }
- public String GetPluginWebsite()
- {
- return "www.BFCinematicTools.com";
- }
- public String GetPluginDescription()
- {
- return "This plugin lets players to vote a map change. Ideal for filming servers.";
- }
- public List<CPluginVariable> GetDisplayPluginVariables()
- {
- List<CPluginVariable> lstReturn = new List<CPluginVariable>();
- lstReturn.Add(new CPluginVariable("Settings|Vote percentage to win", votePercentage.GetType(), votePercentage));
- return lstReturn;
- }
- public List<CPluginVariable> GetPluginVariables()
- {
- return GetDisplayPluginVariables();
- }
- public void SetPluginVariable(String strVariable, String strValue)
- {
- if (Regex.Match(strVariable, @"Vote percentage to win").Success)
- {
- float tmp = 0.66f;
- float.TryParse(strValue, out tmp);
- votePercentage = tmp;
- }
- }
- public void OnPluginEnable()
- {
- ServerCommand("admin.listPlayers", "all");
- this.ExecuteCommand("procon.protected.tasks.add", "1", "300", "-1", "procon.protected.send", "admin.say", "Type !help to list available commands", "all");
- }
- public void OnPluginDisable()
- {
- }
- public override void OnVersion(String serverType, String version) { }
- public override void OnServerInfo(CServerInfo serverInfo)
- {
- }
- public override void OnResponseError(List<String> requestWords, String error) { }
- public override void OnListPlayers(List<CPlayerInfo> players, CPlayerSubset subset)
- {
- playerCount = players.Count;
- }
- public override void OnPlayerJoin(string SoldierName)
- {
- ServerCommand("admin.say", "Welcome! Type !help for available commands", "player", SoldierName);
- }
- public override void OnPlayerLeft(CPlayerInfo playerInfo)
- {
- foreach (string[] vote in Votes)
- {
- if (vote[0] == playerInfo.SoldierName)
- {
- Votes.Remove(vote);
- return;
- }
- }
- foreach (string[] vote in teamVotes)
- {
- if (vote[0] == playerInfo.SoldierName)
- {
- teamVotes.Remove(vote);
- return;
- }
- }
- }
- public override void OnGlobalChat(String speaker, String message)
- {
- parseMessage(speaker, message);
- }
- public override void OnTeamChat(String speaker, String message, int teamId)
- {
- parseMessage(speaker, message);
- }
- public override void OnSquadChat(String speaker, String message, int teamId, int squadId)
- {
- parseMessage(speaker, message);
- }
- public override void OnLoadingLevel(String mapFileName, int roundsPlayed, int roundsTotal)
- {
- Votes.Clear();
- teamVotes.Clear();
- }
- public override void OnLevelStarted()
- {
- }
- public void OnPluginLoaded(String strHostName, String strPort, String strPRoConVersion)
- {
- this.RegisterEvents(this.GetType().Name, "OnVersion", "OnServerInfo", "OnResponseError", "OnListPlayers", "OnPlayerJoin", "OnPlayerLeft", "OnPlayerKilled", "OnPlayerSpawned", "OnPlayerTeamChange", "OnGlobalChat", "OnTeamChat", "OnSquadChat", "OnRoundOverPlayers", "OnRoundOver", "OnRoundOverTeamScores", "OnLoadingLevel", "OnLevelStarted", "OnLevelLoaded");
- }
- }
- } // end namespace PRoConEvents
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement