コード例 #1
0
        public static void SetTime(object sender, string cmd, string[] param,
                                   out Dictionary <string, object> returnVal)
        {
            StringBuilder msgSB = new StringBuilder();

            WorldTime time = WorldTime.Zero;
            float     rate = 0f;
            bool      foundTime = false, foundRate = false;

            for (int i = 0; i < param.Length; i++)
            {
                if ((!foundRate) && (float.TryParse(param[i], out rate)))
                {
                    foundRate = true;
                }
                if ((!foundTime) && (WorldTime.TryParseDayHourMin(param[i], out time)))
                {
                    foundTime = true;
                }
                if (foundTime && foundRate)
                {
                    break;
                }
            }

            if (!(foundTime || foundRate))
            {
                msgSB.Append("No valid WorldTime or rate provided!");
            }
            else
            {
                if (!foundTime)
                {
                    time = WorldInst.List[0].Clock.Time;
                }
                if (!foundRate)
                {
                    rate = WorldInst.List[0].Clock.Rate;
                }
                WorldInst.List[0].Clock.SetTime(time, rate);
                msgSB.Append("Changed WorldTime to: ");
                msgSB.AppendFormat("( time: {0}, rate: {1} )", time, rate);
            }

            returnVal = new Dictionary <string, object>
            {
                { "type", WSProtocolType.chatData },
                { "sender", "SERVER" },
                { "rawText", msgSB.ToString() },
            };
        }