Пример #1
0
        public static string SendEventListAndDetail(string name, string comment, bool IsDetail = true)
        {
            int           num           = 0;
            StringBuilder stringBuilder = new StringBuilder("");

            stringBuilder.AppendFormat("\r\n========== {0} \"{1}\" ==========", comment, name);
            stringBuilder.Append("\r\n========== Event List ==========\r\n");
            foreach (Event @event in EventDataContext.Instance.Event)
            {
                stringBuilder.AppendFormat("{0} [{1}]\r\n", @event.Name, EventDataContext.IsRunning(@event.Name) ? "Running" : "Pending");
                num++;
            }
            stringBuilder.Append("========== Event List ==========");
            if (IsDetail)
            {
                Event event2 = EventDataContext.GetEvent(name);
                if (event2 != null)
                {
                    stringBuilder.AppendFormat("\r\n========== Event Detail ==========\r\nStatus [{0}]\r\n{1}\r\n========== Event Detail ==========", EventDataContext.IsRunning(name) ? "Running" : "Pending", event2.ToStringX());
                }
            }
            stringBuilder.AppendFormat("\r\n========== {0} \"{1}\" ==========", comment, name);
            if (num >= 15)
            {
                stringBuilder.AppendFormat("\r\n========== Warning! Event is more than 15! [Current Count : {0}] ==========", num);
            }
            return(stringBuilder.ToString());
        }
Пример #2
0
        public static bool EndEvent(string name, string scriptend, string msgend, AdminClientServicePeer peer)
        {
            EventDataContext.StartProcessing();
            Event @event = EventDataContext.GetEvent(name);

            if (@event == null)
            {
                if (peer != null)
                {
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Event is Not Registered ! - \"{0}\"", name))));
                }
                return(false);
            }
            if (scriptend != null)
            {
                @event.EndScript = scriptend;
            }
            if (msgend != null)
            {
                @event.EndMessage = msgend;
            }
            EventDataContext.EndEvent(name);
            EventDataContext.RemoveEvent(name);
            if (peer != null)
            {
                string msg = EventDataContext.SendEventListAndDetail(name, "Event is Ended !", false);
                peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, msg)));
            }
            return(true);
        }
Пример #3
0
 public static void SendToFeatureMaxtrixUpdate(int targetServiceID, string category)
 {
     foreach (KeyValuePair <string, Event> keyValuePair in EventDataContext.runnings)
     {
         EventDataContext.SendToStartEvent(keyValuePair.Key, keyValuePair.Value, targetServiceID);
     }
     Log <AdminClientService> .Logger.WarnFormat("Target service featurMatrix update : {0}/{1}", category, targetServiceID);
 }
Пример #4
0
 public static bool ShowEvent(string name, AdminClientServicePeer peer)
 {
     if (peer != null)
     {
         Event @event = EventDataContext.GetEvent(name);
         if (@event != null)
         {
             peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, string.Format("\r\n========== Event Detail ==========\r\nStatus [{0}]\r\n{1}\r\n========== Event Detail ==========", EventDataContext.IsRunning(name) ? "Running" : "Pending", @event.ToStringX()))));
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 private static void SendToStartEvent(string name, Event instance, int targetServiceID)
 {
     if (EventDataContext.IsRunning(name))
     {
         if (instance.StartMessage != null && instance.StartMessage.Length > 0)
         {
             EventDataContext.BroadcastMessage(instance.StartMessage, targetServiceID);
         }
         AdminClientService.Instance.UpdateFeatureMatrix(instance.Feature, true, targetServiceID);
         AdminClientService.Instance.ProcessScript(instance.StartScript, targetServiceID);
         EventDataContext.RearrangeFirstIncomeMessage(targetServiceID);
     }
 }
Пример #6
0
 protected override void OnServiceAdded(string category, int serviceID)
 {
     base.OnServiceAdded(category, serviceID);
     if (AdminClientService.isFirstMicroPlay && category == "MicroPlayServiceCore.MicroPlayService")
     {
         this.RequestResetAllShipList();
         AdminClientService.isFirstMicroPlay = false;
     }
     if (FeatureMatrix.IsEnable("FeatureMatrixSyncService"))
     {
         EventDataContext.AddFeatureMatrixUpdate(serviceID, category);
     }
 }
Пример #7
0
 public static bool ListEvent(AdminClientServicePeer peer)
 {
     if (peer != null)
     {
         string text = "";
         foreach (Event @event in EventDataContext.Instance.Event)
         {
             text += string.Format("{0} [{1}]\r\n", @event.Name, EventDataContext.IsRunning(@event.Name) ? "Running" : "Pending");
         }
         peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, string.Format("\r\n========== Event List ==========\r\n{0}========== Event List ==========", text))));
         return(true);
     }
     return(false);
 }
Пример #8
0
        public static bool RemoveEvent(string name)
        {
            Event @event = EventDataContext.GetEvent(name);

            if (@event != null)
            {
                if (EventDataContext.IsRunning(name))
                {
                    EventDataContext.EndEvent(name);
                }
                return(EventDataContext.RemoveEvent(@event));
            }
            return(false);
        }
Пример #9
0
        public override void Initialize(JobProcessor thread)
        {
            ConnectionStringLoader.LoadFromServiceCore(Settings.Default);
            AdminContents.Initialize();
            this.logger = new HeroesLogDataContext();
            base.Initialize(thread, null);
            base.RegisterMessage(AdminClientServiceOperationMessages.TypeConverters);
            this.acceptor.ClientAccept += this.server_ClientAccept;
            this.acceptor.Start(thread, (int)ServiceCoreSettings.Default.AdminClientServicePort);
            Log <AdminClientService> .Logger.Debug("Starts AdminClientService");

            this.mf.Register <AdminClientServicePeer>(AdminClientServiceOperationMessages.TypeConverters, "ProcessMessage");
            this.controller = new AdminClientServicePeer(this, null);
            EventDataContext.Initialize(thread);
        }
Пример #10
0
        private static void EndEvent(string name)
        {
            Event @event;

            if (EventDataContext.runnings.TryGetValue(name, out @event))
            {
                if (@event.EndMessage != null && @event.EndMessage.Length > 0)
                {
                    EventDataContext.BroadcastMessage(@event.EndMessage, -1);
                }
                AdminClientService.Instance.UpdateFeatureMatrix(@event.Feature, false, -1);
                AdminClientService.Instance.ProcessScript(@event.EndScript, -1);
                EventDataContext.runnings.Remove(name);
                EventDataContext.RearrangeFirstIncomeMessage(-1);
            }
        }
Пример #11
0
 public static void Watcher()
 {
     if (!EventDataContext.processing)
     {
         if (ServiceCore.FeatureMatrix.IsEnable("FeatureMatrixSyncService"))
         {
             EventDataContext.ProcessEvent();
             EventDataContext.processing = true;
             return;
         }
         if (AdminClientService.IsAllServiceReady())
         {
             EventDataContext.StartProcessing();
             return;
         }
         Scheduler.Schedule(EventDataContext.Thread, Job.Create(new Action(EventDataContext.Watcher)), 10000);
     }
 }
Пример #12
0
        private static void RearrangeFirstIncomeMessage(int targetServiceID)
        {
            string text = "";

            foreach (KeyValuePair <string, Event> keyValuePair in EventDataContext.runnings)
            {
                Event value = keyValuePair.Value;
                if (value.NotifyMessage != null && value.NotifyMessage.Length > 0)
                {
                    text += value.NotifyMessage;
                    text += "\r\n";
                }
            }
            if (EventDataContext.FirstIncomeMessage != text)
            {
                EventDataContext.FirstIncomeMessage = text;
                EventDataContext.SetFirstIncomeMessage(EventDataContext.FirstIncomeMessage, targetServiceID);
            }
        }
Пример #13
0
 private static void ProcessEvent()
 {
     try
     {
         DateTime     now   = DateTime.Now;
         int          num   = (now.Hour * 60 + now.Minute) * 60;
         int          num2  = 0;
         List <Event> list  = new List <Event>();
         List <Event> list2 = new List <Event>();
         List <Event> list3 = new List <Event>();
         foreach (Event @event in EventDataContext.Instance.Event)
         {
             if (@event.StartTime == null && !(@event.StartCount > 0))
             {
                 if (@event.EndTime == null || now < @event.EndTime)
                 {
                     list.Add(@event);
                 }
                 else
                 {
                     list3.Add(@event);
                 }
             }
             else if (@event.StartTime != null)
             {
                 if (now >= @event.StartTime)
                 {
                     if (@event.EndTime == null || now < @event.EndTime)
                     {
                         if (@event.PeriodBegin == null)
                         {
                             list.Add(@event);
                         }
                         else if (now.TimeOfDay >= @event.PeriodBegin)
                         {
                             if (@event.PeriodEnd == null || now.TimeOfDay < @event.PeriodEnd)
                             {
                                 list.Add(@event);
                             }
                             else
                             {
                                 list2.Add(@event);
                             }
                         }
                         else
                         {
                             list2.Add(@event);
                         }
                     }
                     else
                     {
                         list3.Add(@event);
                     }
                 }
                 else
                 {
                     list2.Add(@event);
                 }
             }
             else if (@event.StartCount > 0)
             {
                 if (@event.StartCount <= EventDataContext.Instance.GetEventCount(@event.Name))
                 {
                     if (@event.EndTime == null || now < @event.EndTime)
                     {
                         if (@event.PeriodBegin == null)
                         {
                             list.Add(@event);
                         }
                         else if (now.TimeOfDay >= @event.PeriodBegin)
                         {
                             if (@event.PeriodEnd == null || now.TimeOfDay < @event.PeriodEnd)
                             {
                                 list.Add(@event);
                             }
                             else
                             {
                                 list2.Add(@event);
                             }
                         }
                         else
                         {
                             list2.Add(@event);
                         }
                     }
                     else
                     {
                         list3.Add(@event);
                     }
                 }
                 else
                 {
                     list2.Add(@event);
                 }
             }
         }
         foreach (Event event2 in list3)
         {
             EventDataContext.RemoveEvent(event2.Name);
         }
         foreach (Event event3 in list2)
         {
             EventDataContext.EndEvent(event3.Name);
         }
         foreach (KeyValuePair <string, Event> keyValuePair in EventDataContext.runnings)
         {
             Event value = keyValuePair.Value;
             if (value.NotifyMessage != null && value.NotifyMessage.Length > 0)
             {
                 int num3 = 1800;
                 if (value.NotifyInterval != null && value.NotifyInterval.Value >= 0)
                 {
                     num3 = value.NotifyInterval.Value;
                 }
                 num3 = num3 / 60 * 60;
                 if (num3 != 0 && num % num3 == 0)
                 {
                     Scheduler.Schedule(EventDataContext.Thread, Job.Create <string, int>(new Action <string, int>(EventDataContext.BroadcastMessage), value.NotifyMessage, -1), ++num2 * 1000);
                 }
             }
         }
         foreach (Event event4 in list)
         {
             EventDataContext.StartEvent(event4.Name, event4);
         }
         EventDataContext.processed = true;
         foreach (KeyValuePair <int, string> keyValuePair2 in EventDataContext.waitingServiceList)
         {
             Scheduler.Schedule(EventDataContext.Thread, Job.Create <int, string>(new Action <int, string>(EventDataContext.SendToFeatureMaxtrixUpdate), keyValuePair2.Key, keyValuePair2.Value), 10000);
         }
         EventDataContext.waitingServiceList.Clear();
     }
     finally
     {
         EventDataContext.ScheduleNextProcess();
     }
 }
Пример #14
0
        public static bool RegisterEvent(string name, string template, string feature, string scriptstart, string scriptend, DateTime?startTime, DateTime?endTime, TimeSpan?periodBegin, TimeSpan?periodEnd, string msgstart, string msgnotify, string msgend, int msginterval, int startCont, string username, AdminClientServicePeer peer)
        {
            EventDataContext.StartProcessing();
            EventTemplate eventTemplate = null;
            bool          flag          = false;

            if (EventDataContext.IsRunning(name))
            {
                if (peer != null)
                {
                    string msg = EventDataContext.SendEventListAndDetail(name, "Event is Already Running !", true);
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, msg)));
                }
                return(false);
            }
            if (template != null)
            {
                eventTemplate = AdminContents.GetTemplate(template);
                if (eventTemplate == null)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Cannot Find Event Template ! - \"{0}\"", template))));
                    }
                    return(false);
                }
            }
            Event @event = EventDataContext.GetEvent(name);

            if (@event == null)
            {
                @event      = new Event();
                @event.Name = name;
                flag        = true;
            }
            if (eventTemplate != null)
            {
                @event.Feature     = eventTemplate.Feature;
                @event.StartScript = eventTemplate.StartScript;
                @event.EndScript   = eventTemplate.EndScript;
            }
            if (feature != null)
            {
                @event.Feature = feature;
            }
            if (scriptstart != null)
            {
                @event.StartScript = scriptstart;
            }
            if (scriptend != null)
            {
                @event.EndScript = scriptend;
            }
            if (startTime != null)
            {
                if (startTime < DateTime.Now)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Reservation Time Error - \"{0}\"", startTime))));
                    }
                    return(false);
                }
                @event.StartTime = startTime;
            }
            if (endTime != null)
            {
                if (endTime < DateTime.Now)
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Reservation Time Error - \"{0}\"", endTime))));
                    }
                    return(false);
                }
                @event.EndTime = endTime;
            }
            if (periodBegin != null)
            {
                @event.PeriodBegin = periodBegin;
            }
            if (periodEnd != null)
            {
                @event.PeriodEnd = periodEnd;
            }
            if (msgstart != null)
            {
                @event.StartMessage = msgstart;
            }
            if (msgnotify != null)
            {
                @event.NotifyMessage = msgnotify;
            }
            if (msgend != null)
            {
                @event.EndMessage = msgend;
            }
            @event.NotifyInterval = new int?(msginterval);
            @event.StartCount     = new int?(startCont);
            @event.UserName       = username;
            if (flag)
            {
                if (feature != null)
                {
                    string text = EventDataContext.IsExistFeature(feature);
                    if (text != null)
                    {
                        if (peer != null)
                        {
                            peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("That feature is already exist ! - \"{0}\"", text))));
                        }
                        return(false);
                    }
                }
                if (!EventDataContext.AddEvent(@event))
                {
                    if (peer != null)
                    {
                        peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Event Register Failed ! - \"{0}\"", name))));
                    }
                    return(false);
                }
            }
            else if (!EventDataContext.ModifyEvent(@event))
            {
                if (peer != null)
                {
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.ERROR, string.Format("Event Update Failed ! - \"{0}\"", name))));
                }
                return(false);
            }
            if (@event.StartTime == null && !(@event.StartCount > 0))
            {
                EventDataContext.StartEvent(name, @event);
                if (peer != null)
                {
                    string msg2 = EventDataContext.SendEventListAndDetail(name, "Event is Started !", true);
                    peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, msg2)));
                }
            }
            else if (peer != null)
            {
                string msg3 = EventDataContext.SendEventListAndDetail(name, "Event is Reserved !", true);
                peer.Transmit(SerializeWriter.ToBinary <AdminReportNotifyMessage>(new AdminReportNotifyMessage(NotifyCode.SUCCESS, msg3)));
            }
            return(true);
        }
Пример #15
0
        private bool ProcessEventCommand(string args, AdminClientServicePeer peer, int targetServiceID)
        {
            if (args == "goal")
            {
                this.ProcessMicroPlayCommand("monster_kill", "", targetServiceID);
                this.ProcessMicroPlayCommand("autofish_item", "capsule_ap100", targetServiceID);
                return(true);
            }
            CmdTokenizer cmdTokenizer = new CmdTokenizer(args);
            string       next         = cmdTokenizer.GetNext();
            string       next2        = cmdTokenizer.GetNext();
            string       template     = null;
            string       msgstart     = null;
            string       msgnotify    = null;
            string       msgend       = null;
            string       feature      = null;
            string       scriptstart  = null;
            string       scriptend    = null;
            int          msginterval  = 1800;
            int          num          = 0;
            string       username     = "******";
            DateTime?    startTime    = null;
            DateTime?    endTime      = null;
            TimeSpan?    periodBegin  = null;
            TimeSpan?    periodEnd    = null;
            string       text;

            while (cmdTokenizer.GetNext(out text))
            {
                if (text == "template")
                {
                    template = cmdTokenizer.GetNext();
                }
                else if (text == "feature")
                {
                    feature = cmdTokenizer.GetNext();
                }
                else if (text == "scriptstart")
                {
                    scriptstart = cmdTokenizer.GetNext();
                }
                else
                {
                    if (!(text == "scriptend"))
                    {
                        if (text == "starttime")
                        {
                            if (num > 0)
                            {
                                Log <AdminClientService> .Logger.Error("starttime은 startcount와 함께 사용될 수 없습니다.");

                                return(false);
                            }
                            try
                            {
                                string next3 = cmdTokenizer.GetNext();
                                if (next3.Length > 0)
                                {
                                    startTime = new DateTime?(DateTime.Parse(next3));
                                }
                                continue;
                            }
                            catch (Exception ex)
                            {
                                Log <AdminClientService> .Logger.Error("starttime 파싱 도중 에러가 발생했습니다", ex);

                                return(false);
                            }
                        }
                        if (text == "endtime")
                        {
                            try
                            {
                                string next4 = cmdTokenizer.GetNext();
                                if (next4.Length > 0)
                                {
                                    endTime = new DateTime?(DateTime.Parse(next4));
                                }
                                continue;
                            }
                            catch (Exception ex2)
                            {
                                Log <AdminClientService> .Logger.Error("endtime 파싱 도중 에러가 발생했습니다", ex2);

                                return(false);
                            }
                        }
                        if (text == "periodbegin")
                        {
                            try
                            {
                                string next5 = cmdTokenizer.GetNext();
                                if (next5.Length > 0)
                                {
                                    periodBegin = new TimeSpan?(TimeSpan.Parse(next5));
                                }
                                continue;
                            }
                            catch (Exception ex3)
                            {
                                Log <AdminClientService> .Logger.Error("periodbegin 파싱 도중 에러가 발생했습니다", ex3);

                                return(false);
                            }
                        }
                        if (text == "periodend")
                        {
                            try
                            {
                                string next6 = cmdTokenizer.GetNext();
                                if (next6.Length > 0)
                                {
                                    periodEnd = new TimeSpan?(TimeSpan.Parse(next6));
                                }
                                continue;
                            }
                            catch (Exception ex4)
                            {
                                Log <AdminClientService> .Logger.Error("periodend 파싱 도중 에러가 발생했습니다", ex4);

                                return(false);
                            }
                        }
                        if (text == "msgstart")
                        {
                            msgstart = cmdTokenizer.GetNext();
                            continue;
                        }
                        if (text == "msgnotify")
                        {
                            msgnotify = cmdTokenizer.GetNext();
                            continue;
                        }
                        if (text == "msgend")
                        {
                            msgend = cmdTokenizer.GetNext();
                            continue;
                        }
                        if (text == "msginterval")
                        {
                            try
                            {
                                string next7 = cmdTokenizer.GetNext();
                                if (next7.Length > 0)
                                {
                                    msginterval = int.Parse(next7);
                                }
                                continue;
                            }
                            catch (Exception ex5)
                            {
                                Log <AdminClientService> .Logger.Error("msginterval 파싱 도중 에러가 발생했습니다", ex5);

                                return(false);
                            }
                        }
                        if (text == "startcount")
                        {
                            if (startTime != null)
                            {
                                Log <AdminClientService> .Logger.Error("startcount는 starttime과 함께 사용될 수 없습니다.");

                                return(false);
                            }
                            try
                            {
                                string next8 = cmdTokenizer.GetNext();
                                if (next8.Length > 0)
                                {
                                    num = int.Parse(next8);
                                }
                                continue;
                            }
                            catch (Exception ex6)
                            {
                                Log <AdminClientService> .Logger.Error("startcount 파싱 도중 에러가 발생했습니다", ex6);

                                return(false);
                            }
                        }
                        if (text == "username")
                        {
                            username = cmdTokenizer.GetNext();
                            continue;
                        }
                        Log <AdminClientService> .Logger.ErrorFormat("알수 없는 옵션입니다. [{0}]", text);

                        return(false);
                    }
                    scriptend = cmdTokenizer.GetNext();
                }
            }
            if (next == "reg")
            {
                if (next2.Length > 0)
                {
                    return(EventDataContext.RegisterEvent(next2, template, feature, scriptstart, scriptend, startTime, endTime, periodBegin, periodEnd, msgstart, msgnotify, msgend, msginterval, num, username, peer));
                }
            }
            else if (next == "end")
            {
                if (next2.Length > 0)
                {
                    return(EventDataContext.EndEvent(next2, scriptend, msgend, peer));
                }
            }
            else
            {
                if (next == "list")
                {
                    return(EventDataContext.ListEvent(peer));
                }
                if (next == "show")
                {
                    if (next2.Length > 0)
                    {
                        return(EventDataContext.ShowEvent(next2, peer));
                    }
                }
                else if (next == "resume")
                {
                    EventDataContext.StartProcessing();
                }
            }
            return(false);
        }