Example #1
0
        /// <summary>
        /// Adds a socket connection to be tracked by the server
        /// </summary>
        public static bool TrackUserSocket(INetworkConnection client, ref string msg)
        {
            msg = "";
            if (client == null || client.RemoteEndPoint == null)
            {
                return(false);
            }

            if (Clients.ContainsKey(client.RemoteEndPoint as IPEndPoint))
            {
                Clients[client.RemoteEndPoint as IPEndPoint].KillConnection("New connection being made from elsewhere...");
                RemoveConnection(client.RemoteEndPoint as IPEndPoint);
            }

            InboundConnection inb = client as InboundConnection;

            if (inb != null && Clients.Count + 1 > inb.MyServer.MaxInboundConnections)
            {
                msg = "Server is full.";
                return(false);
            }

            Clients.Add(client.UID, client);
            Clients.Associate(client.RemoteEndPoint as IPEndPoint, client.UID);
            PerfMon.IncrementCustomCounter("Live Connections", 1);
            return(true);
        }
Example #2
0
        public static bool RemoveConnection(Guid conId)
        {
            INetworkConnection con = null;

            if (!Clients.TryGetValue(conId, out con))
            {
                return(false);
            }

            if (con == null)
            {
                return(false);
            }

            InboundConnection inb = con as InboundConnection;

            if (inb != null && inb.ServerUser != null)
            {
                inb.ServerUser.MyConnection = null;
            }

            Log1.Logger("Server.Login").Info("Untracking socket " + conId.ToString());

            bool haveIt = false;

            if (Clients.ContainsKey(conId))
            {
                haveIt = true;
                PerfMon.IncrementCustomCounter("Live Connections", -1);
            }

            Clients.Remove(conId);
            return(haveIt);
        }
        private void OnPerfMonStartRequest(INetworkConnection con, Packet r)
        {
            Log1.Logger("Zeus").Debug("Performance Monitor Start request from " + ServerUser.AccountName + ".");

            if (!ServerUser.Profile.IsUserInRole("Administrator"))
            {
                Log1.Logger("Zeus").Warn("[" + ServerUser.AccountName + "] has insufficient permissions to start performance monitor.");
                r.ReplyPacket = CreateStandardReply(r, ReplyType.Failure, "Insufficient permissions. Only Administrators can start the performance monitor.");
                return;
            }

            PacketGenericMessage msg = r as PacketGenericMessage;

            r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, "");
            string[] counters = msg.Parms.GetStringArrayProperty(2);

            if (counters.Length == 0)
            {
                r.ReplyPacket.ReplyCode    = ReplyType.Failure;
                r.ReplyPacket.ReplyMessage = "Must specify at least one counter to start.";
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < counters.Length; i++)
            {
                string      key = counters[i];
                PerfHistory h   = null;
                if (PerfMon.History.TryGetValue(key, out h))
                {
                    h.IsEnabled = true;
                    if (sb.Length == 0)
                    {
                        sb.Append("Enabled performance counter ");
                    }
                    sb.Append(key.Replace("|", " -> ") + ", ");
                }
            }

            if (sb.Length >= 2)
            {
                sb.Remove(sb.Length - 2, 1);
                PerfMon.InstallCounters();
                PerfMon.StartSamplingCounters();
            }
            else if (sb.Length == 0)
            {
                r.ReplyPacket.ReplyCode = ReplyType.Failure;
                sb.Append("No performance counters were activated.");
            }

            r.ReplyPacket.ReplyMessage = sb.ToString();
        }
Example #4
0
 protected override void OnPacketReceived()
 {
     PerfMon.IncrementCustomCounter("Packets In", 1);
 }
Example #5
0
 protected override void OnPacketSent()
 {
     PerfMon.IncrementCustomCounter("Packets Out", 1);
 }
Example #6
0
 protected override void OnBytesReceived(int amount)
 {
     PerfMon.IncrementCustomCounter("Bandwidth In", amount);
 }
Example #7
0
 protected override void OnBytesSent(int amount)
 {
     PerfMon.IncrementCustomCounter("Bandwidth Out", amount);
 }