Example #1
0
        void LoginXmlRpcPostHandler(HttpRequestSignature signature, ref HttpListenerContext context)
        {
            string
                firstName = String.Empty,
                lastName  = String.Empty,
                password  = String.Empty,
                start     = String.Empty,
                version   = String.Empty,
                channel   = String.Empty;

            try
            {
                // Parse the incoming XML
                XmlReader reader = XmlReader.Create(context.Request.InputStream);

                reader.ReadStartElement("methodCall");
                {
                    string methodName = reader.ReadElementContentAsString("methodName", String.Empty);

                    if (methodName == "login_to_simulator")
                    {
                        reader.ReadStartElement("params");
                        reader.ReadStartElement("param");
                        reader.ReadStartElement("value");
                        reader.ReadStartElement("struct");
                        {
                            while (reader.Name == "member")
                            {
                                reader.ReadStartElement("member");
                                {
                                    string name = reader.ReadElementContentAsString("name", String.Empty);

                                    reader.ReadStartElement("value");
                                    {
                                        switch (name)
                                        {
                                        case "first":
                                            firstName = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "last":
                                            lastName = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "passwd":
                                            password = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "start":
                                            start = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "version":
                                            version = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        case "channel":
                                            channel = reader.ReadElementContentAsString("string", String.Empty);
                                            break;

                                        default:
                                            if (reader.Name == "string")
                                            {
                                                Console.WriteLine(String.Format("Ignore login xml value: name={0}, value={1}", name, reader.ReadInnerXml()));
                                            }
                                            else
                                            {
                                                Console.WriteLine(String.Format("Unknown login xml: name={0}, value={1}", name, reader.ReadInnerXml()));
                                            }
                                            break;
                                        }
                                    }
                                    reader.ReadEndElement();
                                }
                                reader.ReadEndElement();
                            }
                        }
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
                reader.Close();

                LoginResponseData responseData = HandleLogin(firstName, lastName, password, start, version, channel);
                if (responseData.Success)
                {
                    responseData.InventorySkeleton = Inventory.CreateInventorySkeleton(responseData.AgentID);
                }
                XmlWriter writer = XmlWriter.Create(context.Response.OutputStream);
                responseData.ToXmlRpc(writer);
                writer.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }