Пример #1
0
        private void OnServerGroupNotified(object sender, EventArgs <AdminReportNotifyMessage> args)
        {
            HeroesAdminPeer peer    = sender as HeroesAdminPeer;
            StringBuilder   builder = new StringBuilder();

            builder.AppendFormat("{0} {1} ", peer.Name, args.Value.Message);
            switch (args.Value.Code)
            {
            case NotifyCode.ERROR:
                builder.Insert(0, "[Error] ");
                builder.AppendLine();
                break;

            case NotifyCode.SUCCESS:
                builder.Append("Success ");
                builder.AppendLine();
                break;

            default:
                builder.AppendLine();
                break;
            }
            if (this.ServerGroupNotified != null)
            {
                this.ServerGroupNotified(sender, new EventArgs <string>(builder.ToString()));
            }
        }
Пример #2
0
        private void OnServerGroupDisconnected(object sender, EventArgs arg)
        {
            HeroesAdminPeer heroesAdminPeer = sender as HeroesAdminPeer;

            if (this.ServerGroupDisconnected != null)
            {
                this.ServerGroupDisconnected(sender, new EventArgs <string>(heroesAdminPeer.Name));
            }
        }
Пример #3
0
 private void ServerGroupActivated(object sender, EventArgs <string> arg)
 {
     if (this.peers.ContainsKey(arg.Value))
     {
         HeroesAdminPeer heroesAdminPeer = this.peers[arg.Value];
         if (!heroesAdminPeer.IsConnected)
         {
             heroesAdminPeer.Start();
         }
     }
 }
Пример #4
0
 public bool SendMessage <T>(string server, T message)
 {
     if (this.peers.ContainsKey(server))
     {
         HeroesAdminPeer heroesAdminPeer = this.peers[server];
         if (heroesAdminPeer.IsConnected)
         {
             this.peers[server].SendMessage <T>(message);
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
        private static void ProcessMessage(object rawMessage, object tag)
        {
            HeroesAdminPeer heroesAdminPeer = tag as HeroesAdminPeer;

            if (rawMessage is AdminReportClientCountMessage2 && heroesAdminPeer.UserCounted != null)
            {
                heroesAdminPeer.UserCounted(heroesAdminPeer, new EventArgs <AdminReportClientCountMessage2>(rawMessage as AdminReportClientCountMessage2));
            }
            if (rawMessage is AdminReportNotifyMessage && heroesAdminPeer.Notified != null)
            {
                AdminReportNotifyMessage value = rawMessage as AdminReportNotifyMessage;
                heroesAdminPeer.Notified(heroesAdminPeer, new EventArgs <AdminReportNotifyMessage>(value));
            }
        }
Пример #6
0
 private void ServerGroupRemoved(object sender, EventArgs <string> arg)
 {
     if (this.peers.ContainsKey(arg.Value))
     {
         HeroesAdminPeer heroesAdminPeer = this.peers[arg.Value];
         heroesAdminPeer.ConnectionSucceed -= this.OnServerGroupConnected;
         heroesAdminPeer.ConnectionFailed  -= new EventHandler <EventArgs <Exception> >(this.OnServerGroupConnectionFailed);
         heroesAdminPeer.Disconnected      -= this.OnServerGroupDisconnected;
         heroesAdminPeer.UserCounted       -= this.OnServerGroupUserCounted;
         heroesAdminPeer.Notified          -= this.OnServerGroupNotified;
         this.peers.Remove(arg.Value);
         heroesAdminPeer.Stop();
     }
 }
Пример #7
0
        private void ServerGroupAdded(object sender, EventArgs <string> arg)
        {
            IPEndPoint ipfromServerGroup = this.client.GetIPFromServerGroup(arg.Value);

            if (ipfromServerGroup != null)
            {
                HeroesAdminPeer heroesAdminPeer = new HeroesAdminPeer(arg.Value, ipfromServerGroup);
                heroesAdminPeer.ConnectionSucceed += this.OnServerGroupConnected;
                heroesAdminPeer.ConnectionFailed  += new EventHandler <EventArgs <Exception> >(this.OnServerGroupConnectionFailed);
                heroesAdminPeer.Disconnected      += this.OnServerGroupDisconnected;
                heroesAdminPeer.UserCounted       += this.OnServerGroupUserCounted;
                heroesAdminPeer.Notified          += this.OnServerGroupNotified;
                heroesAdminPeer.AutoReconnect      = true;
                this.peers.Add(arg.Value, heroesAdminPeer);
                return;
            }
            throw new Exception(string.Format("ServerGroup {0} IP's not found", arg.Value));
        }
Пример #8
0
        private void OnServerGroupUserCounted(object sender, EventArgs <AdminReportClientCountMessage2> args)
        {
            HeroesAdminPeer heroesAdminPeer = sender as HeroesAdminPeer;
            StringBuilder   stringBuilder   = new StringBuilder("uc_stat ");

            foreach (KeyValuePair <string, Dictionary <string, int> > keyValuePair in args.Value.UserCount)
            {
                stringBuilder.AppendFormat("{0}-{1}:", heroesAdminPeer.Name, keyValuePair.Key);
                foreach (KeyValuePair <string, int> keyValuePair2 in keyValuePair.Value)
                {
                    stringBuilder.AppendFormat("{0}({1});", keyValuePair2.Key, keyValuePair2.Value);
                }
                stringBuilder.Append("/");
            }
            if (this.ServerGroupUserCounted != null)
            {
                this.ServerGroupUserCounted(sender, new EventArgs <string>(stringBuilder.ToString()));
            }
        }