Reverted some of plugin method signatures as I realized it didn't really make sense.
This commit is contained in:
parent
45cb985701
commit
2dc8f55e7c
@ -58,14 +58,29 @@ namespace IW4MAdmin
|
||||
|
||||
public void Init()
|
||||
{
|
||||
SharedLibrary.WebService.Init();
|
||||
SharedLibrary.Plugins.PluginImporter.Load(this);
|
||||
|
||||
foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
|
||||
{
|
||||
try
|
||||
{
|
||||
Plugin.OnLoadAsync();
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WriteError($"An error occured loading plugin {Plugin.Name}");
|
||||
Logger.WriteDebug($"Exception: {e.Message}");
|
||||
Logger.WriteDebug($"Stack Trace: {e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
var Configs = Directory.EnumerateFiles("config/servers").Where(x => x.Contains(".cfg"));
|
||||
|
||||
if (Configs.Count() == 0)
|
||||
ServerConfig.Generate();
|
||||
|
||||
SharedLibrary.WebService.Init();
|
||||
SharedLibrary.Plugins.PluginImporter.Load(this);
|
||||
|
||||
foreach (var file in Configs)
|
||||
{
|
||||
var Conf = ServerConfig.Read(file);
|
||||
@ -75,9 +90,6 @@ namespace IW4MAdmin
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
|
||||
await Plugin.OnLoadAsync(ServerInstance);
|
||||
|
||||
await ServerInstance.Initialize();
|
||||
Servers.Add(ServerInstance);
|
||||
|
||||
|
@ -529,8 +529,9 @@ namespace IW4MAdmin
|
||||
throw new SharedLibrary.Exceptions.ServerException($"Invalid gamelog file {logPath}");
|
||||
#endif
|
||||
}
|
||||
|
||||
else
|
||||
logFile = new IFile(logPath);
|
||||
|
||||
Logger.WriteInfo("Log file is " + logPath);
|
||||
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
|
||||
#if !DEBUG
|
||||
|
Binary file not shown.
@ -95,7 +95,7 @@ namespace EventAPI
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnLoadAsync(Server S)
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
APIEvents = new Queue<RestEvent>();
|
||||
flaggedMessagesText = new List<string>();
|
||||
@ -103,7 +103,7 @@ namespace EventAPI
|
||||
WebService.PageList.Add(new EventsJSON());
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync(Server S)
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
APIEvents.Clear();
|
||||
ActiveServers.Clear();
|
||||
|
@ -53,6 +53,10 @@ namespace Plugin
|
||||
{
|
||||
if (E.Type == Event.GType.Start)
|
||||
{
|
||||
ConfigManager.AddConfiguration(S);
|
||||
if (ConfigManager.GetConfiguration(S).Keys.Count == 0)
|
||||
ConfigManager.AddProperty(S, new KeyValuePair<string, object>("Enabled", false));
|
||||
|
||||
try
|
||||
{
|
||||
await S.GetDvarAsync<int>("scr_intermission_time");
|
||||
@ -65,13 +69,9 @@ namespace Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnLoadAsync(Server S)
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
ConfigManager = new ConfigurationManager(typeof(FastRestartPlugin));
|
||||
ConfigManager.AddConfiguration(S);
|
||||
|
||||
if (ConfigManager.GetConfiguration(S).Keys.Count == 0)
|
||||
ConfigManager.AddProperty(S, new KeyValuePair<string, object>("Enabled", false));
|
||||
}
|
||||
|
||||
public async Task OnTickAsync(Server S)
|
||||
@ -92,7 +92,7 @@ namespace Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public Task OnUnloadAsync(Server S)
|
||||
public Task OnUnloadAsync()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -411,8 +411,8 @@ namespace MessageBoard.Forum
|
||||
{
|
||||
//Console.WriteLine("JSON request contains session header - " + requestHeaders["Cookie"]);
|
||||
string cookie = requestHeaders["Cookie"].Split('=')[1];
|
||||
Plugin.Main.forum.startSession(cookie);
|
||||
currentSession = Plugin.Main.forum.getSession(cookie);
|
||||
Plugin.Main.ManagerInstance.startSession(cookie);
|
||||
currentSession = Plugin.Main.ManagerInstance.getSession(cookie);
|
||||
}
|
||||
|
||||
else
|
||||
@ -420,8 +420,8 @@ namespace MessageBoard.Forum
|
||||
string sessionID = Convert.ToBase64String(Encryption.PasswordHasher.GenerateSalt());
|
||||
resp.additionalHeaders.Add("Set-Cookie", "IW4MAdmin_ForumSession=" + sessionID + "; path=/; expires=Sat, 01 May 2025 12:00:00 GMT");
|
||||
currentSession = new Session(new User(), sessionID);
|
||||
Plugin.Main.forum.startSession(sessionID);
|
||||
currentSession = Plugin.Main.forum.getSession(sessionID);
|
||||
Plugin.Main.ManagerInstance.startSession(sessionID);
|
||||
currentSession = Plugin.Main.ManagerInstance.getSession(sessionID);
|
||||
}
|
||||
|
||||
return resp;
|
||||
@ -662,7 +662,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
public override Dictionary<string, string> GetHeaders(IDictionary<string, string> requestHeaders)
|
||||
{
|
||||
Plugin.Main.forum.removeSession(requestHeaders["Cookie"].Split('=')[1]);
|
||||
Plugin.Main.ManagerInstance.removeSession(requestHeaders["Cookie"].Split('=')[1]);
|
||||
return new Dictionary<string, string>() { { "Set-Cookie", "IW4MAdmin_ForumSession=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT" } };
|
||||
}
|
||||
|
||||
@ -711,10 +711,10 @@ namespace MessageBoard.Forum
|
||||
byte[] passwordSalt = Encryption.PasswordHasher.GenerateSalt();
|
||||
string b64PasswordHash = Convert.ToBase64String(Encryption.PasswordHasher.ComputeHash(password, passwordSalt));
|
||||
|
||||
User registeringUser = new User(username, querySet["hiddenUsername"], email, b64PasswordHash, Convert.ToBase64String(passwordSalt), Plugin.Main.forum.UserRank);
|
||||
User registeringUser = new User(username, querySet["hiddenUsername"], email, b64PasswordHash, Convert.ToBase64String(passwordSalt), Plugin.Main.ManagerInstance.UserRank);
|
||||
|
||||
currentSession = new Session(registeringUser, currentSession.sessionID);
|
||||
var addUserResult = Plugin.Main.forum.addUser(registeringUser, currentSession);
|
||||
var addUserResult = Plugin.Main.ManagerInstance.addUser(registeringUser, currentSession);
|
||||
|
||||
if (addUserResult != Manager.ErrorCode.NO_ERROR)
|
||||
{
|
||||
@ -757,8 +757,8 @@ namespace MessageBoard.Forum
|
||||
try
|
||||
{
|
||||
int userid = Convert.ToInt32(querySet["id"]);
|
||||
info.user = Plugin.Main.forum.getUser(userid);
|
||||
info.profile = Plugin.Main.forum.getProfileSettings(userid);
|
||||
info.user = Plugin.Main.ManagerInstance.getUser(userid);
|
||||
info.profile = Plugin.Main.ManagerInstance.getProfileSettings(userid);
|
||||
}
|
||||
|
||||
catch (FormatException)
|
||||
@ -778,7 +778,7 @@ namespace MessageBoard.Forum
|
||||
info.user = currentSession.sessionUser;
|
||||
try
|
||||
{
|
||||
info.profile = Plugin.Main.forum.getProfileSettings(info.user.id);
|
||||
info.profile = Plugin.Main.ManagerInstance.getProfileSettings(info.user.id);
|
||||
}
|
||||
|
||||
catch (Exceptions.UserException)
|
||||
@ -846,7 +846,7 @@ namespace MessageBoard.Forum
|
||||
User existingUser = null;
|
||||
try
|
||||
{
|
||||
existingUser = Plugin.Main.forum.getUser(username);
|
||||
existingUser = Plugin.Main.ManagerInstance.getUser(username);
|
||||
}
|
||||
|
||||
catch (Exceptions.UserException)
|
||||
@ -859,7 +859,7 @@ namespace MessageBoard.Forum
|
||||
aResp.errorCode = Manager.ErrorCode.USER_DUPLICATE;
|
||||
else
|
||||
{
|
||||
var profile = Plugin.Main.forum.getProfileSettings(currentSession.sessionUser.id);
|
||||
var profile = Plugin.Main.ManagerInstance.getProfileSettings(currentSession.sessionUser.id);
|
||||
if (username.Length <= Manager.USERNAME_MAXLENGTH)
|
||||
currentSession.sessionUser.updateUsername(username);
|
||||
else
|
||||
@ -873,10 +873,10 @@ namespace MessageBoard.Forum
|
||||
currentSession.sessionUser.updatePassword(Convert.ToBase64String(passwordSalt), b64PasswordHash);
|
||||
}
|
||||
|
||||
Plugin.Main.forum.updateUser(currentSession.sessionUser);
|
||||
Plugin.Main.ManagerInstance.updateUser(currentSession.sessionUser);
|
||||
if (bannercolor.Length == 7)
|
||||
profile.bannerColor = bannercolor;
|
||||
Plugin.Main.forum.updateUserProfile(profile);
|
||||
Plugin.Main.ManagerInstance.updateUserProfile(profile);
|
||||
|
||||
}
|
||||
}
|
||||
@ -908,7 +908,7 @@ namespace MessageBoard.Forum
|
||||
string username = DNA.Text.TextEngine.Text(querySet["username"]);
|
||||
string password = DNA.Text.TextEngine.Text(querySet["password"]);
|
||||
|
||||
var result = Plugin.Main.forum.authorizeUser(username, password, currentSession.sessionID);
|
||||
var result = Plugin.Main.ManagerInstance.authorizeUser(username, password, currentSession.sessionID);
|
||||
aResp.success = result == Manager.ErrorCode.NO_ERROR;
|
||||
aResp.errorCode = result;
|
||||
aResp.destination = "home";
|
||||
@ -934,7 +934,7 @@ namespace MessageBoard.Forum
|
||||
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
||||
{
|
||||
var resp = base.GetPage(querySet, requestHeaders);
|
||||
var categories = Plugin.Main.forum.getAllCategories();
|
||||
var categories = Plugin.Main.ManagerInstance.getAllCategories();
|
||||
|
||||
|
||||
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categories);
|
||||
@ -956,7 +956,7 @@ namespace MessageBoard.Forum
|
||||
try
|
||||
{
|
||||
List<HomeThread> threads = new List<HomeThread>();
|
||||
var categories = Plugin.Main.forum.getAllCategories();
|
||||
var categories = Plugin.Main.ManagerInstance.getAllCategories();
|
||||
|
||||
foreach (var t in categories)
|
||||
{
|
||||
@ -967,7 +967,7 @@ namespace MessageBoard.Forum
|
||||
thread.categoryTitle = t.title;
|
||||
thread.categoryDescription = t.description;
|
||||
thread.categoryID = t.id;
|
||||
thread.recentThreads = Plugin.Main.forum.getRecentThreads(t.id);
|
||||
thread.recentThreads = Plugin.Main.ManagerInstance.getRecentThreads(t.id);
|
||||
|
||||
threads.Add(thread);
|
||||
}
|
||||
@ -998,12 +998,12 @@ namespace MessageBoard.Forum
|
||||
|
||||
try
|
||||
{
|
||||
var category = Plugin.Main.forum.getCategory(Convert.ToInt32(querySet["id"]));
|
||||
var category = Plugin.Main.ManagerInstance.getCategory(Convert.ToInt32(querySet["id"]));
|
||||
|
||||
if ((category.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
||||
throw new Exceptions.PermissionException("User cannot view this category");
|
||||
|
||||
var categoryThreads = Plugin.Main.forum.getCategoryThreads(category.id);
|
||||
var categoryThreads = Plugin.Main.ManagerInstance.getCategoryThreads(category.id);
|
||||
|
||||
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categoryThreads);
|
||||
return resp;
|
||||
@ -1049,12 +1049,12 @@ namespace MessageBoard.Forum
|
||||
{
|
||||
if (querySet.Get("id") != null)
|
||||
{
|
||||
var thread = Plugin.Main.forum.getThread(Convert.ToInt32(querySet["id"]));
|
||||
var thread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet["id"]));
|
||||
|
||||
if ((thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
||||
throw new Exceptions.PermissionException("User cannot view this post");
|
||||
|
||||
var replies = Plugin.Main.forum.getReplies(thread.id);
|
||||
var replies = Plugin.Main.ManagerInstance.getReplies(thread.id);
|
||||
|
||||
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(new ThreadView(thread, replies));
|
||||
aResp.success = true;
|
||||
@ -1062,7 +1062,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
else if (querySet.Get("replyid") != null)
|
||||
{
|
||||
var thread = Plugin.Main.forum.getReply(Convert.ToInt32(querySet["replyid"]));
|
||||
var thread = Plugin.Main.ManagerInstance.getReply(Convert.ToInt32(querySet["replyid"]));
|
||||
|
||||
//if ((thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
||||
// throw new Exceptions.PermissionException("User cannot view this post");
|
||||
@ -1112,7 +1112,7 @@ namespace MessageBoard.Forum
|
||||
{
|
||||
if (querySet.Get("id") != null)
|
||||
{
|
||||
var thread = Plugin.Main.forum.getThread(Convert.ToInt32(querySet["id"]));
|
||||
var thread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet["id"]));
|
||||
|
||||
if (thread.author.id != currentSession.sessionUser.id && (thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.MODIFY) != Permission.Action.MODIFY)
|
||||
throw new Exceptions.PermissionException("User cannot modify this post");
|
||||
@ -1120,7 +1120,7 @@ namespace MessageBoard.Forum
|
||||
if (querySet.Get("delete") != null)
|
||||
{
|
||||
thread.visible = false;
|
||||
aResp.errorCode = Plugin.Main.forum.updateThread(thread);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.updateThread(thread);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
aResp.destination = "category?id=" + thread.threadCategory.id;
|
||||
}
|
||||
@ -1149,7 +1149,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
if (thread.updateTitle(title) && thread.updateContent(content))
|
||||
{
|
||||
aResp.errorCode = Plugin.Main.forum.updateThread(thread);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.updateThread(thread);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
aResp.destination = "thread?id=" + thread.id;
|
||||
}
|
||||
@ -1161,7 +1161,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
else if (querySet.Get("replyid") != null)
|
||||
{
|
||||
var reply = Plugin.Main.forum.getReply(Convert.ToInt32(querySet["replyid"]));
|
||||
var reply = Plugin.Main.ManagerInstance.getReply(Convert.ToInt32(querySet["replyid"]));
|
||||
|
||||
if (currentSession.sessionUser.id == 0 || reply.author.id != currentSession.sessionUser.id && (reply.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.MODIFY) != Permission.Action.MODIFY)
|
||||
throw new Exceptions.PermissionException("User cannot modify this reply");
|
||||
@ -1169,7 +1169,7 @@ namespace MessageBoard.Forum
|
||||
if (querySet.Get("delete") != null)
|
||||
{
|
||||
reply.visible = false;
|
||||
aResp.errorCode = Plugin.Main.forum.updateReply(reply);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.updateReply(reply);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
aResp.destination = "thread?id=" + reply.threadid;
|
||||
}
|
||||
@ -1199,7 +1199,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
if (reply.updateTitle(title) && reply.updateContent(content))
|
||||
{
|
||||
aResp.errorCode = Plugin.Main.forum.updateReply(reply);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.updateReply(reply);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
aResp.destination = "thread?id=" + threadID;
|
||||
}
|
||||
@ -1265,23 +1265,23 @@ namespace MessageBoard.Forum
|
||||
|
||||
if (querySet.Get("threadid") != null)
|
||||
{
|
||||
var replyThread = Plugin.Main.forum.getThread(Convert.ToInt32(querySet.Get("threadid")));
|
||||
var replyThread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet.Get("threadid")));
|
||||
var reply = new Post(title, replyThread.getID(), content, currentSession.sessionUser);
|
||||
|
||||
aResp.errorCode = Plugin.Main.forum.addPost(replyThread, reply);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.addPost(replyThread, reply);
|
||||
aResp.destination = String.Format("thread?id={0}", replyThread.id);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Category threadCategory = Plugin.Main.forum.getCategory(Convert.ToInt32(querySet["category"]));
|
||||
Category threadCategory = Plugin.Main.ManagerInstance.getCategory(Convert.ToInt32(querySet["category"]));
|
||||
|
||||
if ((threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.WRITE) == Permission.Action.WRITE)
|
||||
{
|
||||
ForumThread newThread = new ForumThread(title, content, currentSession.sessionUser, threadCategory);
|
||||
|
||||
aResp.errorCode = Plugin.Main.forum.addThread(newThread);
|
||||
aResp.errorCode = Plugin.Main.ManagerInstance.addThread(newThread);
|
||||
aResp.destination = String.Format("category?id={0}", threadCategory.id);
|
||||
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
||||
}
|
||||
@ -1328,7 +1328,7 @@ namespace MessageBoard.Forum
|
||||
|
||||
stats.onlineUsers = new List<User>();
|
||||
|
||||
foreach (Session s in Plugin.Main.forum.getSessions())
|
||||
foreach (Session s in Plugin.Main.ManagerInstance.getSessions())
|
||||
{
|
||||
if (s.sessionUser.ranking.id > 0 && (DateTime.Now - s.sessionStartTime).TotalMinutes < 5 && s.sessionUser.username != "Guest")
|
||||
stats.onlineUsers.Add(s.sessionUser);
|
||||
|
@ -7,8 +7,7 @@ namespace MessageBoard.Plugin
|
||||
{
|
||||
public class Main : IPlugin
|
||||
{
|
||||
public static Forum.Manager forum { get; private set; }
|
||||
public static Server stupidServer { get; private set; }
|
||||
public static Forum.Manager ManagerInstance { get; private set; }
|
||||
|
||||
public string Author
|
||||
{
|
||||
@ -36,13 +35,13 @@ namespace MessageBoard.Plugin
|
||||
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
forum = new Forum.Manager();
|
||||
forum.Start();
|
||||
ManagerInstance = new Forum.Manager();
|
||||
ManagerInstance.Start();
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
forum.Stop();
|
||||
ManagerInstance.Stop();
|
||||
}
|
||||
|
||||
public async Task OnTickAsync(Server S)
|
||||
@ -52,11 +51,6 @@ namespace MessageBoard.Plugin
|
||||
|
||||
public async Task OnEventAsync(Event E, Server S)
|
||||
{
|
||||
if (E.Type == Event.GType.Start)
|
||||
{
|
||||
if (stupidServer == null)
|
||||
stupidServer = S;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace MessageBoard
|
||||
public User()
|
||||
{
|
||||
username = "Guest";
|
||||
ranking = Plugin.Main.forum.guestRank;
|
||||
ranking = Plugin.Main.ManagerInstance.guestRank;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -133,12 +133,12 @@ namespace StatsPlugin
|
||||
get { return "RaidMax"; }
|
||||
}
|
||||
|
||||
public async Task OnLoadAsync(Server S)
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
statLists = new List<StatTracking>();
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync(Server S)
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
statLists.Clear();
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ namespace Votemap_Plugin
|
||||
/// <param name="E">This is the `say` event that comes from the server</param>
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
var voting = Vote.getServerVotes(E.Owner.GetPort());
|
||||
var voting = Vote.GetServerVotes(E.Owner.GetPort());
|
||||
|
||||
// we only want to allow a vote during a vote session
|
||||
if (voting.voteInSession)
|
||||
{
|
||||
if (voting.hasVoted(E.Origin.NetworkID))
|
||||
if (voting.ClientHasVoted(E.Origin.NetworkID))
|
||||
await E.Origin.Tell("You have already voted. Use ^5!vc ^7to ^5cancel ^7your vote");
|
||||
else
|
||||
{
|
||||
@ -43,7 +43,7 @@ namespace Votemap_Plugin
|
||||
await E.Origin.Tell("^1" + E.Data + " is not a recognized map");
|
||||
else
|
||||
{
|
||||
voting.castVote(E.Origin.NetworkID, votedMap);
|
||||
voting.CastClientVote(E.Origin.NetworkID, votedMap);
|
||||
await E.Origin.Tell("You voted for ^5" + votedMap.Alias);
|
||||
}
|
||||
}
|
||||
@ -60,13 +60,13 @@ namespace Votemap_Plugin
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
var voting = Vote.getServerVotes(E.Owner.GetPort());
|
||||
var voting = Vote.GetServerVotes(E.Owner.GetPort());
|
||||
|
||||
if (voting.voteInSession)
|
||||
{
|
||||
if (voting.hasVoted(E.Origin.NetworkID))
|
||||
if (voting.ClientHasVoted(E.Origin.NetworkID))
|
||||
{
|
||||
voting.cancelVote(E.Origin.NetworkID);
|
||||
voting.CancelClientVote(E.Origin.NetworkID);
|
||||
await E.Origin.Tell("Vote cancelled");
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ namespace Votemap_Plugin
|
||||
|
||||
public class ServerVoting
|
||||
{
|
||||
public int serverID
|
||||
public int ServerId
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
@ -107,58 +107,63 @@ namespace Votemap_Plugin
|
||||
public bool waitForLoad;
|
||||
public DateTime voteTimeStart;
|
||||
public DateTime loadStartTime;
|
||||
public List<VoteData> voteList
|
||||
public List<VoteData> VoteList
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public ServerVoting(int id)
|
||||
{
|
||||
serverID = id;
|
||||
ServerId = id;
|
||||
voteInSession = false;
|
||||
votePassed = false;
|
||||
matchEnded = false;
|
||||
waitForLoad = true;
|
||||
voteList = new List<VoteData>();
|
||||
VoteList = new List<VoteData>();
|
||||
}
|
||||
|
||||
public int getTotalVotes()
|
||||
public int GetTotalVotes()
|
||||
{
|
||||
return voteList.Count;
|
||||
return VoteList.Count;
|
||||
}
|
||||
|
||||
public bool hasVoted(string guid)
|
||||
public bool ClientHasVoted(string guid)
|
||||
{
|
||||
return voteList.Exists(x => (x.guid == guid));
|
||||
return VoteList.Exists(x => (x.guid == guid));
|
||||
}
|
||||
|
||||
public void castVote(string guid, Map map)
|
||||
public void CastClientVote(string guid, Map map)
|
||||
{
|
||||
var vote = new VoteData();
|
||||
vote.guid = guid;
|
||||
vote.map = map;
|
||||
voteList.Add(vote);
|
||||
}
|
||||
|
||||
public void cancelVote(string guid)
|
||||
var vote = new VoteData()
|
||||
{
|
||||
voteList.RemoveAll(x => (x.guid == guid));
|
||||
guid = guid,
|
||||
map = map
|
||||
};
|
||||
VoteList.Add(vote);
|
||||
}
|
||||
|
||||
public MapResult getTopMap()
|
||||
public void CancelClientVote(string guid)
|
||||
{
|
||||
VoteList.RemoveAll(x => (x.guid == guid));
|
||||
}
|
||||
|
||||
public MapResult GetTopVotedMap()
|
||||
{
|
||||
List<MapResult> results = new List<MapResult>();
|
||||
MapResult result = new MapResult();
|
||||
result.map = new Map("Remain", "Remain");
|
||||
result.voteNum = 0;
|
||||
|
||||
foreach (var vote in voteList)
|
||||
MapResult result = new MapResult()
|
||||
{
|
||||
map = new Map("Remain", "Remain"),
|
||||
voteNum = 0
|
||||
};
|
||||
foreach (var vote in VoteList)
|
||||
{
|
||||
if (!results.Exists(x => (x.map.Name == vote.map.Name)))
|
||||
{
|
||||
MapResult newResult = new MapResult();
|
||||
newResult.map = vote.map;
|
||||
newResult.voteNum = 1;
|
||||
MapResult newResult = new MapResult()
|
||||
{
|
||||
map = vote.map,
|
||||
voteNum = 1
|
||||
};
|
||||
results.Add(newResult);
|
||||
}
|
||||
|
||||
@ -205,12 +210,12 @@ namespace Votemap_Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnLoadAsync(Server S)
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
serverVotingList = new List<ServerVoting>();
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync(Server S)
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
serverVotingList.Clear();
|
||||
}
|
||||
@ -223,7 +228,7 @@ namespace Votemap_Plugin
|
||||
public async Task OnTickAsync(Server S)
|
||||
{
|
||||
return;
|
||||
var serverVotes = getServerVotes(S.GetPort());
|
||||
var serverVotes = GetServerVotes(S.GetPort());
|
||||
|
||||
if (serverVotes != null)
|
||||
{
|
||||
@ -253,7 +258,7 @@ namespace Votemap_Plugin
|
||||
|
||||
if (!serverVotes.voteInSession && serverVotes.votePassed && (DateTime.Now - serverVotes.voteTimeStart).TotalSeconds > 30)
|
||||
{
|
||||
await S.ExecuteCommandAsync("map " + serverVotes.getTopMap().map.Name);
|
||||
await S.ExecuteCommandAsync("map " + serverVotes.GetTopVotedMap().map.Name);
|
||||
serverVotes.votePassed = false;
|
||||
return;
|
||||
}
|
||||
@ -264,14 +269,14 @@ namespace Votemap_Plugin
|
||||
{
|
||||
serverVotes.voteInSession = false;
|
||||
|
||||
MapResult m = serverVotes.getTopMap();
|
||||
MapResult m = serverVotes.GetTopVotedMap();
|
||||
await S.Broadcast("Voting has ended!");
|
||||
|
||||
if (m.voteNum < minVotes && S.GetPlayersAsList().Count > 4)
|
||||
await S.Broadcast("Vote map failed. At least ^5" + minVotes + " ^7people must choose the same map");
|
||||
else
|
||||
{
|
||||
await S.Broadcast(String.Format("Next map is ^5{0} ^7- [^2{1}/{2}^7] votes", m.map.Alias, m.voteNum, serverVotes.getTotalVotes()));
|
||||
await S.Broadcast(String.Format("Next map is ^5{0} ^7- [^2{1}/{2}^7] votes", m.map.Alias, m.voteNum, serverVotes.GetTotalVotes()));
|
||||
serverVotes.votePassed = true;
|
||||
}
|
||||
}
|
||||
@ -289,22 +294,22 @@ namespace Votemap_Plugin
|
||||
|
||||
if (E.Type == Event.GType.Stop)
|
||||
{
|
||||
serverVotingList.RemoveAll(x => x.serverID == S.GetPort());
|
||||
serverVotingList.RemoveAll(x => x.ServerId == S.GetPort());
|
||||
}
|
||||
|
||||
if (E.Type == Event.GType.MapEnd || E.Type == Event.GType.MapChange)
|
||||
{
|
||||
var serverVotes = getServerVotes(S.GetPort());
|
||||
serverVotes.voteList.Clear();
|
||||
var serverVotes = GetServerVotes(S.GetPort());
|
||||
serverVotes.VoteList.Clear();
|
||||
serverVotes.voteTimeStart = DateTime.MinValue;
|
||||
serverVotes.loadStartTime = DateTime.Now;
|
||||
serverVotes.waitForLoad = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static ServerVoting getServerVotes(int serverID)
|
||||
public static ServerVoting GetServerVotes(int serverID)
|
||||
{
|
||||
return serverVotingList.Find(x => (x.serverID == serverID));
|
||||
return serverVotingList.Find(x => (x.ServerId == serverID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,13 +84,13 @@ namespace Welcome_Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnLoadAsync(Server S)
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
PlayerPings = new Dictionary<int, float>();
|
||||
PingAverageCount = 1;
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync(Server S)
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
PlayerPings.Clear();
|
||||
PlayerPings = null;
|
||||
|
@ -22,10 +22,11 @@ namespace SharedLibrary.Helpers
|
||||
ConfigurationSet.Add(S.ToString(), Config);
|
||||
}
|
||||
|
||||
catch(Exceptions.SerializeException)
|
||||
catch (Exceptions.SerializeException)
|
||||
{
|
||||
ConfigurationSet.Add(S.ToString(), new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void AddProperty(Server S, KeyValuePair<string, object> Property)
|
||||
|
@ -5,8 +5,8 @@ namespace SharedLibrary.Interfaces
|
||||
{
|
||||
public interface IPlugin
|
||||
{
|
||||
Task OnLoadAsync(Server S);
|
||||
Task OnUnloadAsync(Server S);
|
||||
Task OnLoadAsync();
|
||||
Task OnUnloadAsync();
|
||||
Task OnEventAsync(Event E, Server S);
|
||||
Task OnTickAsync(Server S);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user