mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make checking for temp rank expiry another scheduler task, instead of a whole separate timer.
This commit is contained in:
parent
1056c06ac4
commit
5948804f11
@ -562,7 +562,6 @@
|
|||||||
<Compile Include="Levels\BlockQueue.cs" />
|
<Compile Include="Levels\BlockQueue.cs" />
|
||||||
<Compile Include="Server\Backup.cs" />
|
<Compile Include="Server\Backup.cs" />
|
||||||
<Compile Include="Server\BackupDB.cs" />
|
<Compile Include="Server\BackupDB.cs" />
|
||||||
<Compile Include="Server\Extra\Checktimer.cs" />
|
|
||||||
<Compile Include="Server\Extra\Scheduler.cs" />
|
<Compile Include="Server\Extra\Scheduler.cs" />
|
||||||
<Compile Include="Server\Extra\UPnP.cs" />
|
<Compile Include="Server\Extra\UPnP.cs" />
|
||||||
<Compile Include="GlobalSuppressions.cs" />
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2011 MCForge
|
|
||||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
|
||||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
|
||||||
not use this file except in compliance with the Licenses. You may
|
|
||||||
obtain a copy of the Licenses at
|
|
||||||
http://www.opensource.org/licenses/ecl2.php
|
|
||||||
http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
|
||||||
software distributed under the Licenses are distributed on an "AS IS"
|
|
||||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
||||||
or implied. See the Licenses for the specific language governing
|
|
||||||
permiusing MCGalaxy;ssions and limitations under the Licenses.
|
|
||||||
*/
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Timers;
|
|
||||||
|
|
||||||
namespace MCGalaxy {
|
|
||||||
|
|
||||||
public static class Checktimer {
|
|
||||||
|
|
||||||
static Timer t;
|
|
||||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
|
||||||
public static void StartTimer() {
|
|
||||||
t = new Timer();
|
|
||||||
t.AutoReset = false;
|
|
||||||
t.Elapsed += TimerElapsed;
|
|
||||||
t.Interval = GetInterval();
|
|
||||||
t.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
static double GetInterval() {
|
|
||||||
DateTime now = DateTime.Now;
|
|
||||||
return ((60 - now.Second) * 1000 - now.Millisecond);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e) {
|
|
||||||
t.Interval = GetInterval();
|
|
||||||
t.Start();
|
|
||||||
TRExpiryCheck(); // every 60 seconds
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TRExpiryCheck() {
|
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
|
||||||
foreach (Player p in players) {
|
|
||||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
|
||||||
if (!line.StartsWith(p.name, comp)) continue;
|
|
||||||
string[] args = line.Split(' ');
|
|
||||||
|
|
||||||
int period = Convert.ToInt32(args[3]);
|
|
||||||
int minutes = Convert.ToInt32(args[4]);
|
|
||||||
int hours = Convert.ToInt32(args[5]);
|
|
||||||
int days = Convert.ToInt32(args[6]);
|
|
||||||
int months = Convert.ToInt32(args[7]);
|
|
||||||
int years = Convert.ToInt32(args[8]);
|
|
||||||
|
|
||||||
DateTime expire = new DateTime(years, months, days, hours, minutes, 0)
|
|
||||||
.AddHours(Convert.ToDouble(period));
|
|
||||||
if (DateTime.Now >= expire)
|
|
||||||
Command.all.Find("temprank").Use(null, p.name + " delete");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -252,7 +252,6 @@ namespace MCGalaxy {
|
|||||||
#endif
|
#endif
|
||||||
Log("Finished setting up server, finding classicube.net url..");
|
Log("Finished setting up server, finding classicube.net url..");
|
||||||
ServerSetupFinished = true;
|
ServerSetupFinished = true;
|
||||||
Checktimer.StartTimer();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Server.lava.startOnStartup)
|
if (Server.lava.startOnStartup)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
||||||
|
Copyright 2011 MCForge
|
||||||
|
|
||||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||||
@ -16,6 +17,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
@ -122,5 +124,31 @@ namespace MCGalaxy {
|
|||||||
all = levels.Join(l => l.name);
|
all = levels.Join(l => l.name);
|
||||||
if (all.Length > 0) Server.s.Log("!LEVELS ONLINE: " + all, true);
|
if (all.Length > 0) Server.s.Log("!LEVELS ONLINE: " + all, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TemprankExpiryTask(SchedulerTask task) {
|
||||||
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
|
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||||
|
|
||||||
|
foreach (Player p in players) {
|
||||||
|
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||||
|
if (!line.StartsWith(p.name, comp)) continue;
|
||||||
|
string[] args = line.Split(' ');
|
||||||
|
|
||||||
|
int period = Convert.ToInt32(args[3]);
|
||||||
|
int minutes = Convert.ToInt32(args[4]);
|
||||||
|
int hours = Convert.ToInt32(args[5]);
|
||||||
|
int days = Convert.ToInt32(args[6]);
|
||||||
|
int months = Convert.ToInt32(args[7]);
|
||||||
|
int years = Convert.ToInt32(args[8]);
|
||||||
|
|
||||||
|
DateTime expire = new DateTime(years, months, days, hours, minutes, 0).AddHours(period);
|
||||||
|
if (DateTime.Now >= expire)
|
||||||
|
Command.all.Find("temprank").Use(null, p.name + " delete");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime now = DateTime.UtcNow;
|
||||||
|
task.Delay = TimeSpan.FromSeconds(60 - now.Second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -115,6 +115,7 @@ namespace MCGalaxy {
|
|||||||
Mods.Clear();
|
Mods.Clear();
|
||||||
Background.QueueOnce(UpdateStaffListTask);
|
Background.QueueOnce(UpdateStaffListTask);
|
||||||
|
|
||||||
|
MainScheduler.QueueRepeat(TemprankExpiryTask, null, TimeSpan.FromSeconds(60));
|
||||||
Background.QueueRepeat(AutoSaveTask, 1,
|
Background.QueueRepeat(AutoSaveTask, 1,
|
||||||
TimeSpan.FromSeconds(Server.backupInterval));
|
TimeSpan.FromSeconds(Server.backupInterval));
|
||||||
Background.QueueRepeat(BlockUpdatesTask, null,
|
Background.QueueRepeat(BlockUpdatesTask, null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user