Ejemplo n.º 1
0
        public async void RemoveSession(long sessionId)
        {
            try
            {
                StartConfigComponent config          = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);

                if (!playerMap.ContainsKey(sessionId))
                {
                    return;
                }
                long userId = playerMap[sessionId];

                var user = UserMap[userId];

                await realmSession.Call(new G2G_QuitSave_Req()
                {
                    UserId = userId
                });

                playerMap.Remove(sessionId);

                Remove(userId);
            }
            catch (System.Exception e)
            {
                Log.Debug($"删除session时发生错误:{e.ToString()}");
            }
        }
Ejemplo n.º 2
0
        private void StartProcess(int appId)
        {
            OptionComponent      optionComponent      = Game.Scene.GetComponent <OptionComponent>();
            StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
            string      configFile  = optionComponent.Options.Config;
            StartConfig startConfig = startConfigComponent.Get(appId);

#if __MonoCS__
            const string exe       = @"dotnet";
            string       arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
#else
            const string exe       = @"dotnet";
            string       arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
#endif

            Log.Info($"{exe} {arguments}");
            try
            {
                ProcessStartInfo info = new ProcessStartInfo {
                    FileName = exe, Arguments = arguments, CreateNoWindow = true, UseShellExecute = true
                };

                Process process = Process.Start(info);
                this.processes.Add(startConfig.AppId, process);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Ejemplo n.º 3
0
        private void StartProcess(int appId)
        {
            OptionComponent      optionComponent      = Game.Scene.GetComponent <OptionComponent>();
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
            string       configFile  = optionComponent.Options.Config;
            StartConfig  startConfig = startConfigComponent.Get(appId);
            const string exe         = "dotnet";
            string       arguments   = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";

            Log.Info($"{exe} {arguments}");
            try
            {
                bool             useShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
                ProcessStartInfo info            = new ProcessStartInfo {
                    FileName = exe, Arguments = arguments, CreateNoWindow = true, UseShellExecute = useShellExecute
                };

                Process process = Process.Start(info);
                this.processes.Add(startConfig.AppId, process);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Ejemplo n.º 4
0
        public void Awake()
        {
            StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

            this.AppId = startConfigComponent.StartConfig.AppId;

            StartConfig startConfig = startConfigComponent.LocationConfig;

            this.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Ejemplo n.º 5
0
        public override async void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            try
            {
                //释放User对象时将User对象从管理组件中移除
                Game.Scene.GetComponent <UserComponent>()?.Remove(this.User.UserID);

                StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>();
                ActorProxyComponent  actorProxyComponent = Game.Scene.GetComponent <ActorProxyComponent>();

                //正在匹配中发送玩家退出匹配请求
                if (this.User.IsMatching)
                {
                    IPEndPoint matchIPEndPoint = config.MatchConfig.GetComponent <InnerConfig>().IPEndPoint;
                    Session    matchSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(matchIPEndPoint);
                    await matchSession.Call(new G2M_PlayerExitMatch_Req()
                    {
                        UserID = this.User.UserID
                    });
                }

                //正在游戏中发送玩家退出房间请求
                if (this.User.ActorID != 0)
                {
                    ActorProxy actorProxy = actorProxyComponent.Get(this.User.ActorID);
                    await actorProxy.Call(new Actor_PlayerExitRoom_Req()
                    {
                        UserID = this.User.UserID
                    });
                }

                //向登录服务器发送玩家下线消息
                IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session    realmSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);
                await realmSession.Call(new G2R_PlayerOffline_Req()
                {
                    UserID = this.User.UserID
                });

                this.User.Dispose();
                this.User = null;
            }
            catch (System.Exception e)
            {
                Log.Trace(e.ToString());
            }
        }
Ejemplo n.º 6
0
        public async void CreateRoom()
        {
            while (roomList.Count == 0)
            {
                await Task.Delay(200);
            }

            StartConfigComponent config          = Game.Scene.GetComponent <StartConfigComponent>();
            IPEndPoint           realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
            Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);

            await realmSession.Call(new G2G_CreateRoom_Req()
            {
            });
        }
        private void StartProcess(int appId)
        {
            OptionComponent      optionComponent      = Game.Scene.GetComponent <OptionComponent>();
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
            string       configFile  = optionComponent.Options.Config;
            StartConfig  startConfig = startConfigComponent.Get(appId);
            const string exe         = "dotnet";
            string       arguments   = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";

            Log.Info($"{exe} {arguments}");
            try
            {
                Process process = ProcessHelper.Run(exe, arguments);
                this.processes.Add(startConfig.AppId, process);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }