Skip to content

Commit

Permalink
-fixed a few bugs
Browse files Browse the repository at this point in the history
-handled possible exception on the onplayerjoined
-removed main MotD handling from the update() function
  • Loading branch information
DraygoKorvan committed Jul 30, 2014
1 parent 3aa6c46 commit c7fb40e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
45 changes: 36 additions & 9 deletions SEMotd/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class SEMotd : PluginBase, IChatEventHandler , IPlayerEventHandler

private DateTime m_lastupdate;
private DateTime m_ruleslastupdate;
private Thread mainloop;
private bool m_running;
SEMotdSettings settings = new SEMotdSettings();

#endregion
Expand All @@ -90,6 +92,11 @@ public override void Init()
loadXML();
m_lastupdate = DateTime.UtcNow;
m_ruleslastupdate = DateTime.UtcNow;
m_running = true;
mainloop = new Thread(main);
mainloop.Priority = ThreadPriority.BelowNormal;
mainloop.Start();

}

#endregion
Expand Down Expand Up @@ -200,7 +207,20 @@ public void loadXML(bool defaults = false)
}

}

public void main()
{
//main execution loop
while(m_running)
{
Thread.Sleep(1000);
if (m_lastupdate + TimeSpan.FromSeconds(interval) < DateTime.UtcNow)
{
m_lastupdate = DateTime.UtcNow;
if (enable)
sendMotd();
}
}
}
public void sendMotd()
{
if(motd != "")
Expand All @@ -215,17 +235,17 @@ public void sendRules()

public override void Update()
{
if(m_lastupdate + TimeSpan.FromSeconds(interval) < DateTime.UtcNow )
{
m_lastupdate = DateTime.UtcNow;
if(enable)
sendMotd();
}

}

public override void Shutdown()
{
m_running = false;
saveXML();
//shut down main loop
mainloop.Join(1000);
mainloop.Abort();

return;
}

Expand Down Expand Up @@ -322,8 +342,15 @@ public void OnChatSent(SEModAPIExtensions.API.ChatManager.ChatEvent obj)

public void OnPlayerJoined(ulong nothing, CharacterEntity character)
{
Thread T = new Thread(() => ChatManager.Instance.SendPrivateChatMessage(character.SteamId, motd));
T.Start();
try
{
Thread T = new Thread(() => ChatManager.Instance.SendPrivateChatMessage(character.SteamId, motd));
T.Start();
}
catch (Exception ex)
{
LogManager.APILog.WriteLineAndConsole("Could not start private message thread. " + ex.ToString());
}
}
public void OnPlayerLeft(ulong nothing, CharacterEntity character)
{
Expand Down
4 changes: 2 additions & 2 deletions SEMotd/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.2.1.2")]
[assembly: AssemblyFileVersion("0.2.1.2")]
[assembly: AssemblyVersion("0.2.1.5")]
[assembly: AssemblyFileVersion("0.2.1.5")]

0 comments on commit c7fb40e

Please sign in to comment.