Exemplo n.º 1
0
        private void OnSend(IAsyncResult asyncResult)
        {
            /* UOGQuery packet sent */
            try {
                m_Socket.EndSend(asyncResult);

                /* receive */
                m_Callback = new AsyncCallback(OnReceive);
                m_Socket.BeginReceive(m_Buffer, 0, m_Buffer.Length,
                                      SocketFlags.None, m_Callback, null);
            } catch (Exception ex) {
                log.Error(String.Format("Could not query game server {0}", m_Config.Name),
                          ex);
                ServerQueryTimer.SetStatus(m_Config, null);
            }
        }
Exemplo n.º 2
0
        private void OnConnect(IAsyncResult asyncResult)
        {
            /* socket connected */
            try {
                m_Socket.EndConnect(asyncResult);

                /* send seed */
                m_Callback = new AsyncCallback(OnSendSeed);
                m_Socket.BeginSend(m_SeedPacket, 0, m_SeedPacket.Length,
                                   SocketFlags.None, m_Callback, null);
            } catch (Exception ex) {
                log.Error(String.Format("Could not query game server {0}", m_Config.Name),
                          ex);
                ServerQueryTimer.SetStatus(m_Config, null);
            }
        }
Exemplo n.º 3
0
        private void OnReceive(IAsyncResult asyncResult)
        {
            /* UOG status received */
            try {
                int byteCount = m_Socket.EndReceive(asyncResult);
                if (byteCount == 0)
                {
                    return;
                }

                String response = new String(Encoding.ASCII.GetChars(m_Buffer, 0, byteCount - 1));

                ServerStatus status = new ServerStatus();
                foreach (string var in response.Split(','))
                {
                    string[] key_value = var.Split('=');
                    if (key_value.Length == 2)
                    {
                        string key   = key_value[0].Trim();
                        string value = key_value[1].Trim();
                        if (key == "Age")
                        {
                            status.age = Int32.Parse(value);
                        }
                        else if (key == "Clients")
                        {
                            status.clients = Int32.Parse(value);
                        }
                        else if (key == "Items")
                        {
                            status.items = Int32.Parse(value);
                        }
                        else if (key == "Chars")
                        {
                            status.chars = Int32.Parse(value);
                        }
                    }
                }

                ServerQueryTimer.SetStatus(m_Config, status);
            } catch (Exception ex) {
                log.Error(String.Format("Could not query game server {0}", m_Config.Name),
                          ex);
                ServerQueryTimer.SetStatus(m_Config, null);
            }
        }
Exemplo n.º 4
0
        public static void UOGQuery(NetState state, PacketReader pvSrc)
        {
            byte cmd = pvSrc.ReadByte();

            if (cmd != 0xFF)
            {
                return;
            }

            Console.WriteLine("Client {0} querying UOG status", state);

            string name = Core.Config.ServerName;

            if (name == null)
            {
                name = "SunUO Login";
            }

            int age     = 0;
            int clients = NetState.Instances.Count;
            int items   = 0;
            int chars   = 0;

            GameServerListConfig gsl = Core.Config.GameServerListConfig;

            if (gsl != null)
            {
                /* add values from game servers */
                foreach (GameServerConfig gs in gsl.GameServers)
                {
                    ServerStatus status = ServerQueryTimer.GetStatus(gs);
                    if (status != null)
                    {
                        age     += status.age;
                        clients += status.clients;
                        items   += status.items;
                        chars   += status.chars;
                    }
                }
            }

            string statStr = String.Format(", Name={0}, Age={1}, Clients={2}, Items={3}, Chars={4}, Mem={5}K", name, age, clients, items, chars, (int)(System.GC.GetTotalMemory(false) / 1024));

            state.Send(new UOGInfo(statStr));
            state.Dispose();
        }