示例#1
0
        /// <summary>
        /// Object Initialization.
        /// </summary>
        public EnvironmentSetting()
        {
            ProductDesEnKey   = productDesEnKey;
            ClientDesDeKey    = clientDesDeKey;
            ProductSignKey    = productSignKey;
            ProductCode       = productCode;
            ProductName       = productName;
            ProductServerId   = productServerId;
            CacheGlobalPeriod = cacheGlobalPeriod;
            CacheUserPeriod   = cacheUserPeriod;

            ScriptSysAsmReferences = scriptSysAsmReferences;
            ScriptAsmReferences    = scriptAsmReferences;
            ActionEnableGZip       = enableActionGZip;
            ActionGZipOutLength    = actionGZipOutLength;
            GamePort       = gamePort;
            GameIpAddress  = gameIpAddress;
            ActionTypeName = actionTypeName;
            ScriptTypeName = scriptTypeName;
            RemoteTypeName = remoteTypeName;
            try
            {
                if (!string.IsNullOrEmpty(entityAssemblyName))
                {
                    EntityAssembly = Assembly.LoadFrom(entityAssemblyName);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Load entity assembly error:\"{0}\" {1}", entityAssemblyName, ex);
            }
            ActionDispatcher = new ScutActionDispatcher();
            Serializer       = serializer;
        }
示例#2
0
        /// <summary>
        /// Object Initialization.
        /// </summary>
        public EnvironmentSetting()
        {
            var appServer     = GetServerSection();
            var protocol      = GetProtocolSection();
            var cacheSection  = GetCacheSection();
            var scriptSection = GetScriptSection();

            CacheGlobalPeriod = cacheSection.ShareExpirePeriod;
            CacheUserPeriod   = cacheSection.PersonalExpirePeriod;

            ScriptSysAsmReferences = scriptSection.SysAssemblyReferences;
            ScriptAsmReferences    = scriptSection.AssemblyReferences;
            GamePort      = protocol.GamePort;
            GameIpAddress = string.IsNullOrEmpty(protocol.GameIpAddress) ? GetLocalIp() : protocol.GameIpAddress;

            try
            {
                if (!string.IsNullOrEmpty(appServer.EntityAssemblyName))
                {
                    EntityAssembly = Assembly.LoadFrom(appServer.EntityAssemblyName);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Load entity assembly error:\"{0}\" {1}", appServer.EntityAssemblyName, ex);
            }
            ActionDispatcher = new ScutActionDispatcher();
            InitSerializer();
            Reset();
        }
        /// <summary>
        /// 执行action
        /// </summary>
        /// <param name="actionType"></param>
        private void SendAction(string actionType, object message = null)
        {
            var actionId = 90016;
            var session  = GameSession.Get(_guid);

            if (session == null)
            {
                session = GameSession.CreateNew(_guid, new HttpRequest("", "http://127.0.0.1", ""));
            }
            var        str1  = DateTime.Now.GetHashCode().ToString();
            var        str2  = ZyGames.Framework.Common.Security.CryptoHelper.MD5_Encrypt(str1 + GMHelper._wordkey, Encoding.UTF8);
            Parameters param = new Parameters();

            param.Add("Word", str1 + ";" + str2);
            param.Add("ActionType", actionType);
            RequestPackage    package          = ActionFactory.GetResponsePackage(actionId, session, param as Parameters, OpCode.Binary, message);
            IActionDispatcher actionDispatcher = new ScutActionDispatcher();

            ActionFactory.GetActionResponse(actionDispatcher, actionId, session, package);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="actionId"></param>
        /// <param name="sessionList"></param>
        /// <param name="package"></param>
        /// <param name="complateHandle"></param>
        /// <param name="onlineInterval"></param>
        /// <returns></returns>
        public static async System.Threading.Tasks.Task BroadcastAction(int actionId, GameSession session, object parameter, Action <GameSession, SocketAsyncResult> complateHandle, int onlineInterval)
        {
            try
            {
                sbyte          opCode  = OpCode.Binary;
                RequestPackage package = parameter is Parameters
                    ? ActionFactory.GetResponsePackage(actionId, session, parameter as Parameters, opCode, null)
                    : ActionFactory.GetResponsePackage(actionId, session, null, opCode, parameter);

                if (session.Equals(null))
                {
                    throw new ArgumentNullException("Session is a null value.");
                }

                IActionDispatcher actionDispatcher = new ScutActionDispatcher();
                package.Bind(session);
                var         actionGetter = new HttpGet(package, session);
                byte[]      data         = ProcessActionResponse(actionDispatcher, actionId, actionGetter);
                GameSession temp         = session;
                try
                {
                    if (onlineInterval <= 0 || session.LastActivityTime > MathUtils.Now.AddSeconds(-onlineInterval))
                    {
                        byte   userRet = 0;
                        string userSid = string.Empty;
                        if (actionGetter.GetByte("UserRet", ref userRet) && userRet == (byte)1 &&
                            actionGetter.GetString("UserSid", ref userSid))
                        {
                            var switchSession = ServerSsMgr.GetSwitchSession();
                            //未连接上路由服,则发给大厅服,由大厅服转发
                            if (switchSession == null)
                            {
                                var    paramStr = "ActionId=100&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await session.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result =>
                                {
                                    if (complateHandle != null)
                                    {
                                        complateHandle(temp, result);
                                    }
                                });
                            }
                            //已连接上路由服,则直接发给路由服
                            else
                            {
                                var    paramStr = "ActionId=101&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await switchSession.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result =>
                                {
                                    if (complateHandle != null)
                                    {
                                        complateHandle(temp, result);
                                    }
                                });
                            }
                        }
                        else
                        {
                            await session.SendAsync(package.OpCode, data, 0, data.Length, result =>
                            {
                                if (complateHandle != null)
                                {
                                    complateHandle(temp, result);
                                }
                            });
                        }
                    }
                    else
                    {
                        if (complateHandle != null)
                        {
                            complateHandle(temp, new SocketAsyncResult(data)
                            {
                                Result = ResultCode.Close
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (complateHandle != null)
                    {
                        complateHandle(temp, new SocketAsyncResult(data)
                        {
                            Result = ResultCode.Error, Error = ex
                        });
                    }
                    TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction  action:{0} userId:{1} error:{2}", actionId, session.UserId, ex);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction  action:{0} error:{1}", actionId, ex);
            }
        }