示例#1
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);
            }
        }
示例#2
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);
            }
        }
示例#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);
            }
        }