Beispiel #1
0
        private void RequestGame(int gameId, string gameName)
        {
            try
            {
                var serverList = new List<ServerInfo>();
                StringBuilder requestParams = new StringBuilder();
                requestParams.AppendFormat("{0}={1}", "ActionID", 1001);
                requestParams.AppendFormat("&{0}={1}", "GameID", gameId);

                Message msg = new Message();
                using (MessageReader msgReader = MessageReader.Create(serverUrl, requestParams.ToString(), msg))
                {
                    if (msgReader == null) return;

                    if (msg.ErrorCode != 10000)
                    {
                        int recordCount = msgReader.RecordCount();

                        for (int i = 0; i < recordCount; i++)
                        {
                            var server = new ServerInfo();
                            msgReader.RecordStart();
                            server.GameID = gameId;
                            server.GameName = gameName;
                            server.ID = msgReader.ReadInt();
                            server.Name = msgReader.ReadString();
                            server.Status = msgReader.ReadString();
                            server.BaseUrl = msgReader.ReadString();
                            server.Weight = msgReader.ReadInt();

                            msgReader.RecordEnd();
                            serverList.Add(server);
                        }
                    }
                    else
                    {
                        Logger.SaveLog(string.Format("Game login monitor >> games {0} service list error", gameName), new Exception(msg.ErrorInfo));
                    }
                }
                foreach (var serverInfo in serverList)
                {
                    ThreadPool.QueueUserWorkItem(RequestServer, serverInfo);
                }
            }
            catch (Exception ex)
            {
                Logger.SaveLog(string.Format("The Game Login surveillance >> read {0} the game hours service list error:", gameName), ex);
                SendToMail(string.Format("读取分服列表异常:{0}", ex.Message));
            }
        }
Beispiel #2
0
        private void RequestServer(object state)
        {
            if (state is ServerInfo)
            {
                var server = state as ServerInfo;
                //Logger.SaveLog(string.Format("游戏登录监视>>{0}[{1}]请求开始", server.GameName, server.Name));
                StringBuilder requestParams = new StringBuilder();
                requestParams.AppendFormat("{0}={1}", "ActionID", 1004);
                requestParams.AppendFormat("&{0}={1}", "Sid", "");
                requestParams.AppendFormat("&{0}={1}", "Uid", "");
                requestParams.AppendFormat("&{0}={1}", "MobileType", 1);
                requestParams.AppendFormat("&{0}={1}", "Pid", GameLogin_Id);
                requestParams.AppendFormat("&{0}={1}", "Pwd", GameLogin_pwd);
                requestParams.AppendFormat("&{0}={1}", "DeviceID", HttpUtility.UrlEncode("00-00-00-00-00-4A", Encoding.UTF8));
                requestParams.AppendFormat("&{0}={1}", "GameType", server.GameID);
                requestParams.AppendFormat("&{0}={1}", "ServerID", server.ID);
                requestParams.AppendFormat("&{0}={1}", "RetailID", "0000");
                requestParams.AppendFormat("&{0}={1}", "RetailUser", "");

                string errorInfo = string.Empty;
                Message msg = new Message();
                using (MessageReader msgReader = MessageReader.Create(server.BaseUrl, requestParams.ToString(), msg))
                {
                    if (msgReader == null) return;

                    if (msg.ErrorCode != 0)
                    {
                        errorInfo = string.Format("游戏登录监视>>{0}[{4}服-{1}]登录出错,Error:{2}-{3}", server.GameName, server.Name, msg.ErrorCode, msg.ErrorInfo, server.ID);
                        Logger.SaveLog(new Exception(errorInfo));

                        //Modify post trace
                        string planName = string.Format("监视游戏:{0},服:{1}登录失败", server.GameName, server.Name);
                        string planValue = string.Format("{0}:{1}", msg.ErrorCode, msg.ErrorInfo);
                        OaSimplePlanHelper.PostDataToServer(planName, planValue);
                    }
                    else
                    {
                        Logger.SaveLog(string.Format("Game login surveillance >> {0} {2} dress - {1}] successful login", server.GameName, server.Name, server.ID));
                    }
                }

                if (!string.IsNullOrEmpty(errorInfo))
                {
                    SendToMail(errorInfo);
                }
            }
        }
Beispiel #3
0
        public static MessageReader Create(string serverUrl, string requestParams, Message header)
        {
            try
            {

                Encoding encode = Encoding.GetEncoding("utf-8");
                string postData = "d=" + GetSign(requestParams);
                byte[] bufferData = encode.GetBytes(postData);

                HttpWebRequest serverRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
                serverRequest.Method = "POST";
                serverRequest.ContentType = "application/x-www-form-urlencoded";
                serverRequest.ContentLength = bufferData.Length;
                Stream requestStream = serverRequest.GetRequestStream();
                requestStream.Write(bufferData, 0, bufferData.Length);
                requestStream.Close();

                //������
                MessageReader msgReader = null;
                WebResponse serverResponse = serverRequest.GetResponse();
                Stream responseStream = serverResponse.GetResponseStream();
                if (responseStream != null)
                {
                    BinaryReader reader = new BinaryReader(responseStream, Encoding.UTF8);
                    msgReader = new MessageReader(reader);

                    header.Length = msgReader.ReadInt();
                    header.ErrorCode = msgReader.ReadInt();
                    header.MsgID = msgReader.ReadInt();
                    header.ErrorInfo = msgReader.ReadString();
                    header.Action = msgReader.ReadInt();
                    header.St = msgReader.ReadString();
                }
                return msgReader;
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(serverUrl + "?" + requestParams, ex);
            }
            return null;
        }