source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/SetTimeReal.cs@ 109

Last change on this file since 109 was 107, checked in by alloc, 10 years ago

fixes

File size: 1.6 KB
Line 
1using System;
2
3public class SetTimeReal : ConsoleCommand
4{
5 public SetTimeReal (ConsoleSdtd cons) : base(cons)
6 {
7 }
8
9 public override string Description ()
10 {
11 return "set current ingame time, params: <day> <hour> <min>";
12 }
13
14 public override string[] Names ()
15 {
16 return new string[] { "settimereal", "str" };
17 }
18
19 public override void Run (string[] _params)
20 {
21 try {
22 if (_params.Length != 3) {
23 m_Console.SendResult ("Usage: settimereal <day> <hour> <min>");
24 return;
25 }
26
27 int day, hour, min;
28 if (!int.TryParse (_params [0], out day)) {
29 m_Console.SendResult ("Could not parse day number \"" + _params [0] + "\"");
30 return;
31 }
32 if (day < 1) {
33 m_Console.SendResult ("Day must be >= 1");
34 return;
35 }
36 if (!int.TryParse (_params [1], out hour)) {
37 m_Console.SendResult ("Could not parse hour \"" + _params [1] + "\"");
38 return;
39 }
40 if (hour > 23) {
41 m_Console.SendResult ("Hour must be <= 23");
42 return;
43 }
44 if (!int.TryParse (_params [2], out min)) {
45 m_Console.SendResult ("Could not parse minute \"" + _params [2] + "\"");
46 return;
47 }
48 if (min > 59) {
49 m_Console.SendResult ("Minute must be <= 59");
50 return;
51 }
52 if ((day < 1) || (hour < 8 && day < 1)) {
53 m_Console.SendResult ("Time may not be prior to day 1, 8:00");
54 return;
55 }
56
57 ulong time = ((ulong)(day - 1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000;
58 m_Console.gameManager.World.gameTime = time;
59 m_Console.SendResult (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time));
60 } catch (Exception e) {
61 Log.Out ("Error in SetTimeReal.Run: " + e);
62 }
63 }
64}
65
Note: See TracBrowser for help on using the repository browser.