Exemplo n.º 1
0
        public async void OnLogin()
        {
            try
            {
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);

                string text = this.account.GetComponent <InputField>().text;

                R2C_Login r2CLogin;
                using (Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint))
                {
                    r2CLogin = (R2C_Login)await session.Call(new C2R_Login()
                    {
                        Account = text, Password = "******"
                    });
                }

                connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                ETModel.Game.Scene.AddComponent <SessionComponent>().Session = gateSession;
                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                playerComponent.MyPlayer = player;

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
            }
            catch (Exception e)
            {
                Log.Error(e.ToStr());
            }
        }
        protected override void Run(Session session, G2G_LockReleaseRequest message, Action <G2G_LockReleaseResponse> reply)
        {
            G2G_LockReleaseResponse g2GLockReleaseResponse = new G2G_LockReleaseResponse();

            try
            {
                Unit unit = Game.Scene.GetComponent <UnitComponent>().Get(message.Id);
                if (unit == null)
                {
                    g2GLockReleaseResponse.Error = ErrorCode.ERR_NotFoundUnit;
                    reply(g2GLockReleaseResponse);
                    return;
                }

                unit.GetComponent <MasterComponent>().Release(NetworkHelper.ToIPEndPoint(message.Address));
                reply(g2GLockReleaseResponse);
            }
            catch (Exception e)
            {
                ReplyError(g2GLockReleaseResponse, e, reply);
            }
        }
        private async void OnRegister()
        {
            try
            {
                this.accountText  = this.account.GetComponent <InputField>().text;
                this.passwordText = this.password.GetComponent <InputField>().text;
                if (String.IsNullOrWhiteSpace(accountText) || string.IsNullOrWhiteSpace(passwordText))
                {
                    Log.Error("账号或者密码为空");
                    return;
                }

                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);

                Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = new SessionWrap(session);
                R2C_Register register = (R2C_Register)await sessionWrap.Call(new C2R_Register()
                {
                    Account = accountText, Password = passwordText
                });

                switch (register.Error)
                {
                case ErrorCode.ERR_Success:
                    Log.Info("成功注册");
                    break;

                case ErrorCode.ERR_AccountExist:
                    Log.Error("用户名已被注册");
                    break;
                }
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e.ToStr());
            }
        }
Exemplo n.º 4
0
        protected async ETVoid RunAsync(Session session, G2G_LockRequest message, Action <G2G_LockResponse> reply)
        {
            G2G_LockResponse response = new G2G_LockResponse();

            try
            {
                Unit unit = Game.Scene.GetComponent <UnitComponent>().Get(message.Id);
                if (unit == null)
                {
                    response.Error = ErrorCode.ERR_NotFoundUnit;
                    reply(response);
                    return;
                }

                await unit.GetComponent <MasterComponent>().Lock(NetworkHelper.ToIPEndPoint(message.Address));

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public override void Run()
        {
            var lobbyComponent = Game.Scene.GetComponent <LobbyComponent>();

            if (lobbyComponent == null)
            {
                Console.WriteLine("LobbyComponent is null");
                return;
            }

            var cacheProxyComponent = Game.Scene.GetComponent <CacheProxyComponent>();
            var memorySync          = cacheProxyComponent.GetMemorySyncSolver <Player>();

            foreach (var data in memorySync.Data)
            {
                Player player = data.Value as Player;
                if (!player.isOnline)
                {
                    NetworkHelper.DisconnectPlayer(player);
                }
            }
            Console.WriteLine($"ok");
        }
Exemplo n.º 6
0
        private async void OnClickPressTest()
        {
            Session sessionWrap = null;

            try
            {
                //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                IPEndPoint      connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.4.158:10006");
                ETModel.Session session        = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                G2C_PressTest g2C_PressTest = (G2C_PressTest)await sessionWrap.Call(new C2G_PressTest());

                UINetLoadingComponent.closeNetLoading();

                sessionWrap.Dispose();
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e);
            }
        }
Exemplo n.º 7
0
        public async void OnLogin()
        {
            try
            {
                //
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);


                // 创建一个ETModel层的Session
                ETModel.Session session      = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Session         realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);

                /*
                 * 请求登录
                 */
                R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account  = this.account.GetComponent <InputField>().text,
                    Password = this.password.GetComponent <InputField>().text
                }
                                                                        );

                realmSession.Dispose();

                /*
                 * 处理登录结果
                 */
                if (r2CLogin.Error == ErrorCode.ERR_Success)
                {
                    connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                    // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中"111.230.133.20:10002"
                    ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                    ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                    // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                    Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                    G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                    {
                        Key = r2CLogin.Key
                    });

                    Log.Info("登陆gate成功!");

                    // 创建Player
                    Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
                    PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                    playerComponent.MyPlayer = player;

                    Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                    Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
                }
                else if (r2CLogin.Error == ErrorCode.ERR_AccountInvaild)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号中有不法字符~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_PasswordInvaild)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码中有不法字符~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_PasswordIncorrect)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码不正确~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_AccountNotExist)
                {
                    UIAlertsGrayComponent l = Game.Scene.GetComponent <UIAlertsGrayComponent>();
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号不存在~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_DataBaseRead)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("网络异常~", onAlertCbLoginFail, "好的~");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 8
0
        public async Task OnThirdLogin(string third_id, string name, string head)
        {
            //加锁
            if (isLogining)
            {
                return;
            }
            isLogining = true;

            Session sessionWrap = null;

            try
            {
                UINetLoadingComponent.showNetLoading();

                // IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                IPEndPoint connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
#if Localhost
                connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002");
#endif
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                name = name.Replace("'", "*");
                R2C_ThirdLogin r2CLogin = (R2C_ThirdLogin)await sessionWrap.Call(new C2R_ThirdLogin()
                {
                    Third_Id = third_id, MachineId = PlatformHelper.GetMacId(), ChannelName = PlatformHelper.GetChannelName(), ClientVersion = PlatformHelper.GetVersionName(), Name = name, Head = head
                });

                sessionWrap.Dispose();

                UINetLoadingComponent.closeNetLoading();

                if (r2CLogin.Error != ErrorCode.ERR_Success)
                {
                    ToastScript.createToast(r2CLogin.Message);
                    return;
                }

                UINetLoadingComponent.showNetLoading();

                // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
//                connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
                string[] temp = r2CLogin.Address.Split(':');
                connetEndPoint = ToIPEndPointWithYuMing(Convert.ToInt32(temp[1]));

                // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);

#if Localhost
                connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002");
#endif

                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(session);
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession;

                // Log.Info("gateSession:"+ connetEndPoint.ToString());
                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                ToastScript.createToast("登录成功");
                //挂心跳包
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>();
                UINetLoadingComponent.closeNetLoading();

                await getAllData();

                isLoginSuccess = true;

                Game.Scene.GetComponent <PlayerInfoComponent>().uid = g2CLoginGate.Uid;

                PlayerInfoComponent.Instance.SetShopInfoList(g2CLoginGate.ShopInfoList);
                PlayerInfoComponent.Instance.SetBagInfoList(g2CLoginGate.BagList);
                PlayerInfoComponent.Instance.ownIcon = g2CLoginGate.ownIcon;

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIMain);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
                isLogining = false;
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error("OnThirdLogin:" + e);
                isLogining = false;
            }
        }
Exemplo n.º 9
0
        protected async override void Run(Session session, C2S_UserLogin message, Action <S2C_UserLogin> reply)
        {
            S2C_UserLogin response = new S2C_UserLogin();
            //从local获取一个map地址
            var ret = await Game.Scene.GetComponent <LocationProxyComponent>().GetMapAddress(1);

            if (ret.Tag != 0)
            {
                response.Tag = ret.Tag;
                reply(response);
            }
            Session        mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(NetworkHelper.ToIPEndPoint(ret.Address));
            M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit()
            {
                AccountId = message.AccountId, GateSessionId = session.InstanceId
            });

            Player player = ComponentFactory.Create <Player, int>(message.AccountId);

            player.UnitId = createUnit.UnitId;
            Log.Debug("数据库结束:" + createUnit);
            Game.Scene.GetComponent <PlayerManagerComponent>().Add(player);
            session.AddComponent <SessionPlayerComponent>().Player = player;
            session.AddComponent <MailBoxComponent, string>(ActorType.GateSession);
            response.Tag    = 0;
            response.UnitId = createUnit.UnitId;
            reply(response);

            Log.Debug("数据库结束");
            count++;
        }
        /// <summary>
        /// 登录按钮事件
        /// </summary>
        public async void OnLogin()
        {
            if (isLogining || this.IsDisposed)
            {
                return;
            }
            NetOuterComponent netOuterComponent = Game.Scene.ModelScene.GetComponent <NetOuterComponent>();

            //设置登录中状态
            isLogining = true;
            Session sessionWrap = null;

            try
            {
                //创建登录服务器连接
                IPEndPoint      connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                ETModel.Session session        = netOuterComponent.Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);
                sessionWrap.session.GetComponent <SessionCallbackComponent>().DisposeCallback += s =>
                {
                    if (Game.Scene.GetComponent <UIComponent>()?.Get(UIType.LandlordsLogin) != null)
                    {
                        prompt.text = "连接失败";
                        isLogining  = false;
                    }
                };

                //发送登录请求
                prompt.text = "正在登录中....";
                R2C_Login_Ack r2C_Login_Ack = await sessionWrap.Call(new C2R_Login_Req()
                {
                    Account = account.text, Password = password.text
                }) as R2C_Login_Ack;

                prompt.text = "";

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2C_Login_Ack.Error == ErrorCode.ERR_LoginError)
                {
                    prompt.text   = "登录失败,账号或密码错误";
                    password.text = "";
                    return;
                }

                //创建Gate服务器连接
                connetEndPoint = NetworkHelper.ToIPEndPoint(r2C_Login_Ack.Address);
                ETModel.Session gateSession = netOuterComponent.Create(connetEndPoint);
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);
                //SessionWeap添加连接断开组件,用于处理客户端连接断开
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>();
                Game.Scene.ModelScene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                //登录Gate服务器
                G2C_LoginGate_Ack g2C_LoginGate_Ack = await SessionComponent.Instance.Session.Call(new C2G_LoginGate_Req()
                {
                    Key = r2C_Login_Ack.Key
                }) as G2C_LoginGate_Ack;

                if (g2C_LoginGate_Ack.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    prompt.text   = "连接网关服务器超时";
                    password.text = "";
                    Game.Scene.GetComponent <SessionComponent>().Session.Dispose();
                    return;
                }

                Log.Info("登录成功");

                //保存本地玩家
                User user = ETModel.ComponentFactory.CreateWithId <User, long>(g2C_LoginGate_Ack.PlayerID, g2C_LoginGate_Ack.UserID);
                ClientComponent.Instance.LocalPlayer = user;

                //跳转到大厅界面
                Game.Scene.GetComponent <UIComponent>().Create(UIType.LandlordsLobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.LandlordsLogin);
            }
            catch (Exception e)
            {
                prompt.text = "登录异常";
                Log.Error(e.ToStr());
            }
            finally
            {
                //断开验证服务器的连接
                sessionWrap.Dispose();
                //设置登录处理完成状态
                isLogining = false;
            }
        }
Exemplo n.º 11
0
        public async void OnVisitorLogin()
        {
            if (isLogining || this.IsDisposed)
            {
                return;
            }
            NetOuterComponent netOuterComponent = ETModel.Game.Scene.GetComponent <NetOuterComponent>();

            //设置登录中状态
            isLogining = true;
            SessionWrap sessionWrap = null;

            try
            {
                string macAddress = SystemInfo.deviceUniqueIdentifier;
                if (!Define.IsEditorMode)
                {
                    macAddress += System.DateTime.Now.ToString();
                }
                string password = "******";

                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                Session    session        = netOuterComponent.Create(connetEndPoint);
                sessionWrap = new SessionWrap(session);
                sessionWrap.session.GetComponent <SessionCallbackComponent>().DisposeCallback += s =>
                {
                    if (Game.Scene.GetComponent <UIComponent>()?.Get(UIType.UILogin) != null)
                    {
                        isLogining = false;
                    }
                };

                R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login()
                {
                    Account = macAddress, Password = password
                });

                sessionWrap.Dispose();

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2CLogin.Error == ErrorCode.ERR_AccountOrPasswordError)
                {
                    return;
                }

                connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                Session gateSession = netOuterComponent.Create(connetEndPoint);
                Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession);
                //SessionWeap添加连接断开组件,用于处理客户端连接断开
                Game.Scene.GetComponent <SessionWrapComponent>().Session.AddComponent <SessionOfflineComponent>();
                ETModel.Game.Scene.AddComponent <SessionComponent>().Session = gateSession;
                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionWrapComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                if (g2CLoginGate.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    Game.Scene.GetComponent <SessionWrapComponent>().Session.Dispose();
                    return;
                }

                Log.Info("登陆gate成功!");

                //保存本地玩家
                User user = ETModel.ComponentFactory.CreateWithId <User, long>(g2CLoginGate.PlayerId, g2CLoginGate.UserId);
                ClientComponent.Instance.LocalPlayer = user;

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e);
            }
            finally
            {
                //断开验证服务器的连接
                netOuterComponent.Remove(sessionWrap.session.Id);
                //设置登录处理完成状态
                isLogining = false;
            }
        }
        private async ETTask RunAsync(Player player, C2L_TeamCreate message, Action <L2C_TeamCreate> reply)
        {
            L2C_TeamCreate response = new L2C_TeamCreate();

            try
            {
                var lobbyComponent = Game.Scene.GetComponent <LobbyComponent>();

                User user = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault());

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_AccountDoesntExist;
                    reply(response);
                    return;
                }

                // 判斷是否還在舊的房間
                if (player.roomID != 0L)
                {
                    // 如果有就強制退房
                    await lobbyComponent.LeaveRoom(player.roomID, player.uid);
                }

                int roomcount = lobbyComponent.GetTeamRoomCount();
                if (roomcount >= lobbyComponent.GetMaxTeamRoomLimitCount())
                {
                    response.Error = ErrorCode.ERR_TooManyRooms;
                    reply(response);
                    return;
                }

                RoomInfo roomInfo = new RoomInfo()
                {
                    RoomId         = 0,
                    Title          = user.name,
                    RoadSettingId  = message.RoadSettingId,
                    MaxMemberCount = 8,
                    NowMemberCount = 0,
                };

                TeamRoomData teamRoomData = new TeamRoomData()
                {
                    LeaderUid        = player.uid,
                    LeaderName       = user.name,
                    StartUTCTimeTick = -1,
                };

                // 隨機一個Map給要預約的房間
                var startConfig = NetworkHelper.GetRandomMap();
                var room        = await lobbyComponent.CreateTeamRoom(startConfig.AppId, roomInfo, teamRoomData);

                if (room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                if (room.Type != RoomType.Team)
                {
                    response.Error = ErrorCode.ERR_RoonTypeError;
                    reply(response);
                    return;
                }

                // 連接到Map伺服器,並創建Unit實體
                Session mapSession = SessionHelper.GetMapSession(startConfig.AppId);

                // 建立Map實體並進入房間
                L2M_MapUnitCreate m2L_MapUnitCreate = new L2M_MapUnitCreate();
                m2L_MapUnitCreate.Uid           = player.uid;
                m2L_MapUnitCreate.GateSessionId = player.gateSessionActorId;
                m2L_MapUnitCreate.MapUnitInfo   = new MapUnitInfo()
                {
                    Name              = user.name,
                    Location          = user.location,
                    RoomId            = room.Id,
                    DistanceTravelled = 0,
                    CharSetting       = user.playerCharSetting,
                    // PathId 一般組隊入場再決定
                };

                // 建立自身MapUnit
                M2L_MapUnitCreate createUnit = (M2L_MapUnitCreate)await mapSession.Call(m2L_MapUnitCreate);

                player.EnterRoom(createUnit.MapUnitId, room);

                // 得到隊伍資訊
                var teamInfo = await lobbyComponent.GetTeamInfo(room.Id);

                if (teamInfo == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }

                // 更新PlayerUnit
                var playerComponent = Game.Scene.GetComponent <PlayerComponent>();
                await playerComponent.Update(player);

                // 回傳資料
                response.Info        = room.info;
                response.Data        = teamInfo.Item1;
                response.MemberDatas = teamInfo.Item2;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }