Пример #1
0
        public override void OnGetRequest(HttpListenerRequest request, HttpListenerResponse response)
        {
            string url = request.Url.PathAndQuery;

            if (url.Contains("?"))
            {
                url = url.Substring(0, url.IndexOf("?"));
                url = url.ToLower();
            }
            try
            {
                switch (url)
                {
                case "/":
                    WriteResponse(response, GameLanguage.GameName);
                    break;

                case "/regist":
                    string id                  = request.QueryString["id"].ToString();
                    string psd                 = request.QueryString["psd"].ToString();
                    string email               = request.QueryString["email"].ToString();
                    string name                = request.QueryString["name"].ToString();
                    string question            = request.QueryString["question"].ToString();
                    string answer              = request.QueryString["answer"].ToString();
                    string ip                  = request.QueryString["ip"].ToString();
                    ClientPackets.NewAccount p = new ClientPackets.NewAccount();
                    p.AccountID      = id;
                    p.Password       = psd;
                    p.EMailAddress   = email;
                    p.UserName       = name;
                    p.SecretQuestion = question;
                    p.SecretAnswer   = answer;
                    int result = SMain.Envir.HTTPNewAccount(p, ip);
                    WriteResponse(response, result.ToString());
                    break;

                case "/login":
                    id     = request.QueryString["id"].ToString();
                    psd    = request.QueryString["psd"].ToString();
                    result = SMain.Envir.HTTPLogin(id, psd);
                    WriteResponse(response, result.ToString());
                    break;

                case "/addnamelist":
                    id = request.QueryString["id"].ToString();
                    string fileName = request.QueryString["fileName"].ToString();
                    addNameList(id, fileName);
                    WriteResponse(response, "true");
                    break;

                default:
                    WriteResponse(response, "error");
                    break;
                }
            }
            catch (Exception error)
            {
                WriteResponse(response, "request error: " + error);
            }
        }
Пример #2
0
        public override void OnGetRequest(HttpListenerRequest request, HttpListenerResponse response)
        {
            var url = request.Url.PathAndQuery;

            if (url.Contains("?"))
            {
                url = url.Substring(0, url.IndexOf("?", StringComparison.Ordinal));
                url = url.ToLower();
            }
            try
            {
                switch (url)
                {
                case "/":
                    WriteResponse(response, GameLanguage.GameName);
                    break;

                case "/newaccount":
                    var id       = request.QueryString["id"];
                    var psd      = request.QueryString["psd"];
                    var email    = request.QueryString["email"];
                    var name     = request.QueryString["name"];
                    var question = request.QueryString["question"];
                    var answer   = request.QueryString["answer"];
                    var ip       = request.QueryString["ip"];
                    var p        = new ClientPackets.NewAccount();
                    p.AccountID      = id;
                    p.Password       = psd;
                    p.EMailAddress   = email;
                    p.UserName       = name;
                    p.SecretQuestion = question;
                    p.SecretAnswer   = answer;
                    var result = Envir.Main.HTTPNewAccount(p, ip);
                    WriteResponse(response, result.ToString());
                    break;

                case "/addnamelist":
                    id = request.QueryString["id"];
                    var fileName = request.QueryString["fileName"];
                    AddNameList(id, fileName);
                    WriteResponse(response, "true");
                    break;

                case "/broadcast":
                    var msg = request.QueryString["msg"];
                    if (msg.Length < 5)
                    {
                        WriteResponse(response, "short");
                        return;
                    }
                    Envir.Main.Broadcast(new S.Chat
                    {
                        Message = msg.Trim(),
                        Type    = ChatType.Shout2
                    });
                    WriteResponse(response, "true");
                    break;

                default:
                    WriteResponse(response, "error");
                    break;
                }
            }
            catch (Exception error)
            {
                WriteResponse(response, "request error: " + error);
            }
        }