Reverted some of plugin method signatures as I realized it didn't really make sense.

This commit is contained in:
RaidMax 2017-06-13 18:33:47 -04:00
parent 45cb985701
commit 2dc8f55e7c
13 changed files with 122 additions and 109 deletions

View File

@ -58,14 +58,29 @@ namespace IW4MAdmin
public void Init() 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")); var Configs = Directory.EnumerateFiles("config/servers").Where(x => x.Contains(".cfg"));
if (Configs.Count() == 0) if (Configs.Count() == 0)
ServerConfig.Generate(); ServerConfig.Generate();
SharedLibrary.WebService.Init();
SharedLibrary.Plugins.PluginImporter.Load(this);
foreach (var file in Configs) foreach (var file in Configs)
{ {
var Conf = ServerConfig.Read(file); var Conf = ServerConfig.Read(file);
@ -75,9 +90,6 @@ namespace IW4MAdmin
{ {
try try
{ {
foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
await Plugin.OnLoadAsync(ServerInstance);
await ServerInstance.Initialize(); await ServerInstance.Initialize();
Servers.Add(ServerInstance); Servers.Add(ServerInstance);

View File

@ -529,8 +529,9 @@ namespace IW4MAdmin
throw new SharedLibrary.Exceptions.ServerException($"Invalid gamelog file {logPath}"); throw new SharedLibrary.Exceptions.ServerException($"Invalid gamelog file {logPath}");
#endif #endif
} }
else
logFile = new IFile(logPath);
logFile = new IFile(logPath);
Logger.WriteInfo("Log file is " + logPath); Logger.WriteInfo("Log file is " + logPath);
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this)); await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
#if !DEBUG #if !DEBUG

Binary file not shown.

View File

@ -95,7 +95,7 @@ namespace EventAPI
} }
} }
public async Task OnLoadAsync(Server S) public async Task OnLoadAsync()
{ {
APIEvents = new Queue<RestEvent>(); APIEvents = new Queue<RestEvent>();
flaggedMessagesText = new List<string>(); flaggedMessagesText = new List<string>();
@ -103,7 +103,7 @@ namespace EventAPI
WebService.PageList.Add(new EventsJSON()); WebService.PageList.Add(new EventsJSON());
} }
public async Task OnUnloadAsync(Server S) public async Task OnUnloadAsync()
{ {
APIEvents.Clear(); APIEvents.Clear();
ActiveServers.Clear(); ActiveServers.Clear();

View File

@ -53,6 +53,10 @@ namespace Plugin
{ {
if (E.Type == Event.GType.Start) 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 try
{ {
await S.GetDvarAsync<int>("scr_intermission_time"); 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 = 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) public async Task OnTickAsync(Server S)
@ -92,7 +92,7 @@ namespace Plugin
} }
} }
public Task OnUnloadAsync(Server S) public Task OnUnloadAsync()
{ {
return null; return null;
} }

View File

@ -411,8 +411,8 @@ namespace MessageBoard.Forum
{ {
//Console.WriteLine("JSON request contains session header - " + requestHeaders["Cookie"]); //Console.WriteLine("JSON request contains session header - " + requestHeaders["Cookie"]);
string cookie = requestHeaders["Cookie"].Split('=')[1]; string cookie = requestHeaders["Cookie"].Split('=')[1];
Plugin.Main.forum.startSession(cookie); Plugin.Main.ManagerInstance.startSession(cookie);
currentSession = Plugin.Main.forum.getSession(cookie); currentSession = Plugin.Main.ManagerInstance.getSession(cookie);
} }
else else
@ -420,8 +420,8 @@ namespace MessageBoard.Forum
string sessionID = Convert.ToBase64String(Encryption.PasswordHasher.GenerateSalt()); 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"); resp.additionalHeaders.Add("Set-Cookie", "IW4MAdmin_ForumSession=" + sessionID + "; path=/; expires=Sat, 01 May 2025 12:00:00 GMT");
currentSession = new Session(new User(), sessionID); currentSession = new Session(new User(), sessionID);
Plugin.Main.forum.startSession(sessionID); Plugin.Main.ManagerInstance.startSession(sessionID);
currentSession = Plugin.Main.forum.getSession(sessionID); currentSession = Plugin.Main.ManagerInstance.getSession(sessionID);
} }
return resp; return resp;
@ -662,7 +662,7 @@ namespace MessageBoard.Forum
public override Dictionary<string, string> GetHeaders(IDictionary<string, string> requestHeaders) 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" } }; 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(); byte[] passwordSalt = Encryption.PasswordHasher.GenerateSalt();
string b64PasswordHash = Convert.ToBase64String(Encryption.PasswordHasher.ComputeHash(password, passwordSalt)); 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); 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) if (addUserResult != Manager.ErrorCode.NO_ERROR)
{ {
@ -757,8 +757,8 @@ namespace MessageBoard.Forum
try try
{ {
int userid = Convert.ToInt32(querySet["id"]); int userid = Convert.ToInt32(querySet["id"]);
info.user = Plugin.Main.forum.getUser(userid); info.user = Plugin.Main.ManagerInstance.getUser(userid);
info.profile = Plugin.Main.forum.getProfileSettings(userid); info.profile = Plugin.Main.ManagerInstance.getProfileSettings(userid);
} }
catch (FormatException) catch (FormatException)
@ -778,7 +778,7 @@ namespace MessageBoard.Forum
info.user = currentSession.sessionUser; info.user = currentSession.sessionUser;
try try
{ {
info.profile = Plugin.Main.forum.getProfileSettings(info.user.id); info.profile = Plugin.Main.ManagerInstance.getProfileSettings(info.user.id);
} }
catch (Exceptions.UserException) catch (Exceptions.UserException)
@ -846,7 +846,7 @@ namespace MessageBoard.Forum
User existingUser = null; User existingUser = null;
try try
{ {
existingUser = Plugin.Main.forum.getUser(username); existingUser = Plugin.Main.ManagerInstance.getUser(username);
} }
catch (Exceptions.UserException) catch (Exceptions.UserException)
@ -859,7 +859,7 @@ namespace MessageBoard.Forum
aResp.errorCode = Manager.ErrorCode.USER_DUPLICATE; aResp.errorCode = Manager.ErrorCode.USER_DUPLICATE;
else 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) if (username.Length <= Manager.USERNAME_MAXLENGTH)
currentSession.sessionUser.updateUsername(username); currentSession.sessionUser.updateUsername(username);
else else
@ -873,10 +873,10 @@ namespace MessageBoard.Forum
currentSession.sessionUser.updatePassword(Convert.ToBase64String(passwordSalt), b64PasswordHash); currentSession.sessionUser.updatePassword(Convert.ToBase64String(passwordSalt), b64PasswordHash);
} }
Plugin.Main.forum.updateUser(currentSession.sessionUser); Plugin.Main.ManagerInstance.updateUser(currentSession.sessionUser);
if (bannercolor.Length == 7) if (bannercolor.Length == 7)
profile.bannerColor = bannercolor; 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 username = DNA.Text.TextEngine.Text(querySet["username"]);
string password = DNA.Text.TextEngine.Text(querySet["password"]); 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.success = result == Manager.ErrorCode.NO_ERROR;
aResp.errorCode = result; aResp.errorCode = result;
aResp.destination = "home"; aResp.destination = "home";
@ -934,7 +934,7 @@ namespace MessageBoard.Forum
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders) public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
{ {
var resp = base.GetPage(querySet, 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); resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categories);
@ -956,7 +956,7 @@ namespace MessageBoard.Forum
try try
{ {
List<HomeThread> threads = new List<HomeThread>(); List<HomeThread> threads = new List<HomeThread>();
var categories = Plugin.Main.forum.getAllCategories(); var categories = Plugin.Main.ManagerInstance.getAllCategories();
foreach (var t in categories) foreach (var t in categories)
{ {
@ -967,7 +967,7 @@ namespace MessageBoard.Forum
thread.categoryTitle = t.title; thread.categoryTitle = t.title;
thread.categoryDescription = t.description; thread.categoryDescription = t.description;
thread.categoryID = t.id; thread.categoryID = t.id;
thread.recentThreads = Plugin.Main.forum.getRecentThreads(t.id); thread.recentThreads = Plugin.Main.ManagerInstance.getRecentThreads(t.id);
threads.Add(thread); threads.Add(thread);
} }
@ -998,12 +998,12 @@ namespace MessageBoard.Forum
try 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) 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"); 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); resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categoryThreads);
return resp; return resp;
@ -1049,12 +1049,12 @@ namespace MessageBoard.Forum
{ {
if (querySet.Get("id") != null) 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) 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"); 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)); resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(new ThreadView(thread, replies));
aResp.success = true; aResp.success = true;
@ -1062,7 +1062,7 @@ namespace MessageBoard.Forum
else if (querySet.Get("replyid") != null) 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) //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"); // throw new Exceptions.PermissionException("User cannot view this post");
@ -1112,7 +1112,7 @@ namespace MessageBoard.Forum
{ {
if (querySet.Get("id") != null) 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) 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"); throw new Exceptions.PermissionException("User cannot modify this post");
@ -1120,7 +1120,7 @@ namespace MessageBoard.Forum
if (querySet.Get("delete") != null) if (querySet.Get("delete") != null)
{ {
thread.visible = false; 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.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
aResp.destination = "category?id=" + thread.threadCategory.id; aResp.destination = "category?id=" + thread.threadCategory.id;
} }
@ -1149,7 +1149,7 @@ namespace MessageBoard.Forum
if (thread.updateTitle(title) && thread.updateContent(content)) 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.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
aResp.destination = "thread?id=" + thread.id; aResp.destination = "thread?id=" + thread.id;
} }
@ -1161,7 +1161,7 @@ namespace MessageBoard.Forum
else if (querySet.Get("replyid") != null) 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) 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"); throw new Exceptions.PermissionException("User cannot modify this reply");
@ -1169,7 +1169,7 @@ namespace MessageBoard.Forum
if (querySet.Get("delete") != null) if (querySet.Get("delete") != null)
{ {
reply.visible = false; 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.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
aResp.destination = "thread?id=" + reply.threadid; aResp.destination = "thread?id=" + reply.threadid;
} }
@ -1199,7 +1199,7 @@ namespace MessageBoard.Forum
if (reply.updateTitle(title) && reply.updateContent(content)) 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.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
aResp.destination = "thread?id=" + threadID; aResp.destination = "thread?id=" + threadID;
} }
@ -1265,23 +1265,23 @@ namespace MessageBoard.Forum
if (querySet.Get("threadid") != null) 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); 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.destination = String.Format("thread?id={0}", replyThread.id);
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR; aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
} }
else 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) 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); 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.destination = String.Format("category?id={0}", threadCategory.id);
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR; aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
} }
@ -1328,7 +1328,7 @@ namespace MessageBoard.Forum
stats.onlineUsers = new List<User>(); 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") if (s.sessionUser.ranking.id > 0 && (DateTime.Now - s.sessionStartTime).TotalMinutes < 5 && s.sessionUser.username != "Guest")
stats.onlineUsers.Add(s.sessionUser); stats.onlineUsers.Add(s.sessionUser);

View File

@ -7,8 +7,7 @@ namespace MessageBoard.Plugin
{ {
public class Main : IPlugin public class Main : IPlugin
{ {
public static Forum.Manager forum { get; private set; } public static Forum.Manager ManagerInstance { get; private set; }
public static Server stupidServer { get; private set; }
public string Author public string Author
{ {
@ -36,13 +35,13 @@ namespace MessageBoard.Plugin
public async Task OnLoadAsync() public async Task OnLoadAsync()
{ {
forum = new Forum.Manager(); ManagerInstance = new Forum.Manager();
forum.Start(); ManagerInstance.Start();
} }
public async Task OnUnloadAsync() public async Task OnUnloadAsync()
{ {
forum.Stop(); ManagerInstance.Stop();
} }
public async Task OnTickAsync(Server S) public async Task OnTickAsync(Server S)
@ -52,11 +51,6 @@ namespace MessageBoard.Plugin
public async Task OnEventAsync(Event E, Server S) public async Task OnEventAsync(Event E, Server S)
{ {
if (E.Type == Event.GType.Start)
{
if (stupidServer == null)
stupidServer = S;
}
} }
} }
} }

View File

@ -27,7 +27,7 @@ namespace MessageBoard
public User() public User()
{ {
username = "Guest"; username = "Guest";
ranking = Plugin.Main.forum.guestRank; ranking = Plugin.Main.ManagerInstance.guestRank;
} }
/// <summary> /// <summary>

View File

@ -133,12 +133,12 @@ namespace StatsPlugin
get { return "RaidMax"; } get { return "RaidMax"; }
} }
public async Task OnLoadAsync(Server S) public async Task OnLoadAsync()
{ {
statLists = new List<StatTracking>(); statLists = new List<StatTracking>();
} }
public async Task OnUnloadAsync(Server S) public async Task OnUnloadAsync()
{ {
statLists.Clear(); statLists.Clear();
} }

View File

@ -27,12 +27,12 @@ namespace Votemap_Plugin
/// <param name="E">This is the `say` event that comes from the server</param> /// <param name="E">This is the `say` event that comes from the server</param>
public override async Task ExecuteAsync(Event E) 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 // we only want to allow a vote during a vote session
if (voting.voteInSession) 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"); await E.Origin.Tell("You have already voted. Use ^5!vc ^7to ^5cancel ^7your vote");
else else
{ {
@ -43,7 +43,7 @@ namespace Votemap_Plugin
await E.Origin.Tell("^1" + E.Data + " is not a recognized map"); await E.Origin.Tell("^1" + E.Data + " is not a recognized map");
else else
{ {
voting.castVote(E.Origin.NetworkID, votedMap); voting.CastClientVote(E.Origin.NetworkID, votedMap);
await E.Origin.Tell("You voted for ^5" + votedMap.Alias); await E.Origin.Tell("You voted for ^5" + votedMap.Alias);
} }
} }
@ -60,13 +60,13 @@ namespace Votemap_Plugin
public override async Task ExecuteAsync(Event E) 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.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"); await E.Origin.Tell("Vote cancelled");
} }
@ -97,7 +97,7 @@ namespace Votemap_Plugin
public class ServerVoting public class ServerVoting
{ {
public int serverID public int ServerId
{ {
get; private set; get; private set;
} }
@ -107,58 +107,63 @@ namespace Votemap_Plugin
public bool waitForLoad; public bool waitForLoad;
public DateTime voteTimeStart; public DateTime voteTimeStart;
public DateTime loadStartTime; public DateTime loadStartTime;
public List<VoteData> voteList public List<VoteData> VoteList
{ {
get; private set; get; private set;
} }
public ServerVoting(int id) public ServerVoting(int id)
{ {
serverID = id; ServerId = id;
voteInSession = false; voteInSession = false;
votePassed = false; votePassed = false;
matchEnded = false; matchEnded = false;
waitForLoad = true; 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(); var vote = new VoteData()
vote.guid = guid; {
vote.map = map; guid = guid,
voteList.Add(vote); map = map
};
VoteList.Add(vote);
} }
public void cancelVote(string guid) public void CancelClientVote(string guid)
{ {
voteList.RemoveAll(x => (x.guid == guid)); VoteList.RemoveAll(x => (x.guid == guid));
} }
public MapResult getTopMap() public MapResult GetTopVotedMap()
{ {
List<MapResult> results = new List<MapResult>(); List<MapResult> results = new List<MapResult>();
MapResult result = new MapResult(); MapResult result = new MapResult()
result.map = new Map("Remain", "Remain"); {
result.voteNum = 0; map = new Map("Remain", "Remain"),
voteNum = 0
foreach (var vote in voteList) };
foreach (var vote in VoteList)
{ {
if (!results.Exists(x => (x.map.Name == vote.map.Name))) if (!results.Exists(x => (x.map.Name == vote.map.Name)))
{ {
MapResult newResult = new MapResult(); MapResult newResult = new MapResult()
newResult.map = vote.map; {
newResult.voteNum = 1; map = vote.map,
voteNum = 1
};
results.Add(newResult); results.Add(newResult);
} }
@ -205,12 +210,12 @@ namespace Votemap_Plugin
} }
} }
public async Task OnLoadAsync(Server S) public async Task OnLoadAsync()
{ {
serverVotingList = new List<ServerVoting>(); serverVotingList = new List<ServerVoting>();
} }
public async Task OnUnloadAsync(Server S) public async Task OnUnloadAsync()
{ {
serverVotingList.Clear(); serverVotingList.Clear();
} }
@ -223,7 +228,7 @@ namespace Votemap_Plugin
public async Task OnTickAsync(Server S) public async Task OnTickAsync(Server S)
{ {
return; return;
var serverVotes = getServerVotes(S.GetPort()); var serverVotes = GetServerVotes(S.GetPort());
if (serverVotes != null) if (serverVotes != null)
{ {
@ -253,7 +258,7 @@ namespace Votemap_Plugin
if (!serverVotes.voteInSession && serverVotes.votePassed && (DateTime.Now - serverVotes.voteTimeStart).TotalSeconds > 30) 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; serverVotes.votePassed = false;
return; return;
} }
@ -264,14 +269,14 @@ namespace Votemap_Plugin
{ {
serverVotes.voteInSession = false; serverVotes.voteInSession = false;
MapResult m = serverVotes.getTopMap(); MapResult m = serverVotes.GetTopVotedMap();
await S.Broadcast("Voting has ended!"); await S.Broadcast("Voting has ended!");
if (m.voteNum < minVotes && S.GetPlayersAsList().Count > 4) if (m.voteNum < minVotes && S.GetPlayersAsList().Count > 4)
await S.Broadcast("Vote map failed. At least ^5" + minVotes + " ^7people must choose the same map"); await S.Broadcast("Vote map failed. At least ^5" + minVotes + " ^7people must choose the same map");
else 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; serverVotes.votePassed = true;
} }
} }
@ -289,22 +294,22 @@ namespace Votemap_Plugin
if (E.Type == Event.GType.Stop) 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) if (E.Type == Event.GType.MapEnd || E.Type == Event.GType.MapChange)
{ {
var serverVotes = getServerVotes(S.GetPort()); var serverVotes = GetServerVotes(S.GetPort());
serverVotes.voteList.Clear(); serverVotes.VoteList.Clear();
serverVotes.voteTimeStart = DateTime.MinValue; serverVotes.voteTimeStart = DateTime.MinValue;
serverVotes.loadStartTime = DateTime.Now; serverVotes.loadStartTime = DateTime.Now;
serverVotes.waitForLoad = true; 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));
} }
} }
} }

View File

@ -84,13 +84,13 @@ namespace Welcome_Plugin
} }
} }
public async Task OnLoadAsync(Server S) public async Task OnLoadAsync()
{ {
PlayerPings = new Dictionary<int, float>(); PlayerPings = new Dictionary<int, float>();
PingAverageCount = 1; PingAverageCount = 1;
} }
public async Task OnUnloadAsync(Server S) public async Task OnUnloadAsync()
{ {
PlayerPings.Clear(); PlayerPings.Clear();
PlayerPings = null; PlayerPings = null;

View File

@ -22,10 +22,11 @@ namespace SharedLibrary.Helpers
ConfigurationSet.Add(S.ToString(), Config); ConfigurationSet.Add(S.ToString(), Config);
} }
catch(Exceptions.SerializeException) catch (Exceptions.SerializeException)
{ {
ConfigurationSet.Add(S.ToString(), new Dictionary<string, object>()); ConfigurationSet.Add(S.ToString(), new Dictionary<string, object>());
} }
} }
public void AddProperty(Server S, KeyValuePair<string, object> Property) public void AddProperty(Server S, KeyValuePair<string, object> Property)

View File

@ -5,8 +5,8 @@ namespace SharedLibrary.Interfaces
{ {
public interface IPlugin public interface IPlugin
{ {
Task OnLoadAsync(Server S); Task OnLoadAsync();
Task OnUnloadAsync(Server S); Task OnUnloadAsync();
Task OnEventAsync(Event E, Server S); Task OnEventAsync(Event E, Server S);
Task OnTickAsync(Server S); Task OnTickAsync(Server S);