Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="userList"></param>
        /// <param name="actionId"></param>
        /// <param name="parameters"></param>
        /// <param name="successHandle"></param>
        public void SendAsyncAction <T>(List <T> userList, int actionId, Parameters parameters, Action <HttpGet> successHandle) where T : BaseUser
        {
            StringBuilder shareParam = new StringBuilder();

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    shareParam.AppendFormat("&{0}={1}", parameter.Key, parameter.Value);
                }
            }
            foreach (var user in userList)
            {
                try
                {
                    if (user == default(T))
                    {
                        continue;
                    }
                    HttpGet httpGet;
                    byte[]  sendData = ActionFactory.GetActionResponse(actionId, user, shareParam.ToString(), out httpGet);
                    SendAsync(user.SocketSid, sendData);
                    if (httpGet != null)
                    {
                        successHandle(httpGet);
                    }
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("SendToClient error:{0}", ex);
                }
            }
        }
Exemple #2
0
        private void OnHttpRequestTimeout(object state)
        {
            try
            {
                HttpClientConnection clientConnection = (HttpClientConnection)state;
                if (clientConnection == null)
                {
                    return;
                }

                int    actionId = 0;
                string action;
                if (clientConnection.Param.TryGetValue("ActionId", out action))
                {
                    actionId = action.ToInt();
                }

                var httpresponse = new SocketGameResponse();
                ActionFactory.RequestError(httpresponse, actionId, "Request Timeout.");
                byte[] respData = httpresponse.ReadByte();
                OnHttpResponse(clientConnection, respData, 0, respData.Length);
            }
            catch
            {
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="actionGetter"></param>
 /// <param name="response"></param>
 protected void DoAction(ActionGetter actionGetter, BaseGameResponse response)
 {
     if (GameEnvironment.IsOnMainTain)
     {
         //判断是否白名单
         bool isWhite = false;
         var  session = actionGetter.Session;
         if (session != null)
         {
             if (!string.IsNullOrEmpty(session.RemoteAddress))
             {
                 if (session.RemoteAddress.Contains("192.168."))
                 {
                     isWhite = true;
                 }
                 if (!isWhite)
                 {
                     var address = session.RemoteAddress.Split(':');
                     if ((GameEnvironment.MainTainWhiteIpSet.Contains(address[0])))
                     {
                         isWhite = true;
                     }
                 }
             }
             if (!isWhite)
             {
                 if (GameEnvironment.MainTainWhiteUserIdSet.Contains(session.UserId))
                 {
                     isWhite = true;
                 }
             }
         }
         //
         if (!isWhite)
         {
             response.WriteError(actionGetter, Language.Instance.ErrorCode, Language.Instance.ServerMaintain);
             return;
         }
     }
     //
     if (!GameEnvironment.IsRedisReady)
     {
         response.WriteError(actionGetter, Language.Instance.ErrorCode, Language.Instance.ServerBusy);
     }
     else if (GameEnvironment.IsRunning)
     {
         OnRequested(actionGetter, response);
         ActionFactory.Request(actionGetter, response);
     }
     else
     {
         response.WriteError(actionGetter, Language.Instance.MaintainCode, Language.Instance.ServerMaintain);
     }
 }
Exemple #4
0
 /// <summary>
 /// Raises the requested event.
 /// </summary>
 /// <param name="actionGetter">Http get.</param>
 /// <param name="response">Response.</param>
 protected virtual void OnRequested(ActionGetter actionGetter, BaseGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         ActionFactory.Request(actionGetter, response, GetUser);
     }
     else
     {
         response.WriteError(actionGetter, Language.Instance.ErrorCode, Language.Instance.ServerMaintain);
     }
 }
Exemple #5
0
 /// <summary>
 /// Raises the requested event.
 /// </summary>
 /// <param name="httpGet">Http get.</param>
 /// <param name="response">Response.</param>
 protected virtual void OnRequested(HttpGet httpGet, IGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         ActionFactory.Request(httpGet, response, GetUser);
     }
     else
     {
         ActionFactory.RequestError(response, httpGet.ActionId, Language.Instance.ServerMaintain);
     }
 }
Exemple #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="actionGetter"></param>
 /// <param name="response"></param>
 protected void DoAction(ActionGetter actionGetter, BaseGameResponse response)
 {
     if (GameEnvironment.IsRunning)
     {
         OnRequested(actionGetter, response);
         ActionFactory.Request(actionGetter, response);
     }
     else
     {
         response.WriteError(actionGetter, Language.Instance.MaintainCode, Language.Instance.ServerMaintain);
     }
 }