private async ETVoid GetPlayer(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } User user = Game.Scene.GetComponent <UserComponent>().Get(account); List <Player> players = await Game.Scene.GetComponent <PlayerComponent>().GetPlayerByIds(user.playerids); Player player = players[0]; session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(response); Console.WriteLine(" C2G_LoginGateHandler-35-playerId: " + player.Id); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { //在Gate服务器中对传递过来的key进行验证 (每20秒KEY失效) string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } //传进用户帐号 Player player = ComponentFactory.Create <Player, string>(account); Game.Scene.GetComponent <PlayerComponent>().Add(player); //添加到用户管理组件 session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(ActorInterceptType.GateSession); response.PlayerId = player.Id; //给客户端返回的用户ID reply(response); //给客户端发送热更测试 session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + MethodBase.GetCurrentMethod().Name + "Gate key验证失败!"; reply(response); return; } Player player = ComponentFactory.Create <Player, string>(account); Game.Scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Session session, LoginGate_C2G request, LoginGate_G2C response, Action reply) { try { SessionKeyComponent SessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>(); // 获取玩家的UserID long gateUserID = SessionKeyComponent.Get(request.GateLoginKey); // 验证登录Key是否正确 if (gateUserID == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; //客户端提示:连接网关服务器超时 reply(); return; } //Key过期 SessionKeyComponent.Remove(request.GateLoginKey); // gateUserID传参创建User User user = ComponentFactory.Create <User, long>(gateUserID); // 将新上线的User添加到UserComponent容器中 Game.Scene.GetComponent <UserComponent>().Add(user); user.AddComponent <MailBoxComponent>(); // session挂SessionUser组件,user绑定到session上 session.AddComponent <SessionUserComponent>().User = user; // session挂MailBox组件可以通过MailBox进行actor通信 session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); // 构建realmSession通知Realm服务器 玩家已上线 StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint; Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint); // 2个参数 1:UserID 2:GateAppID realmSession.Send(new PlayerOnline_G2R() { UserId = user.UserId, GateAppId = config.StartConfig.AppId }); // 设置User的参数 user.GateAppId = config.StartConfig.AppId; user.GateSessionId = session.InstanceId; user.ActorId = 0; // session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); // 回复客户端 response.UserId = user.UserId; reply(); await ETTask.CompletedTask; } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { Scene scene = Game.Scene.Get(request.GateId); if (scene == null) { return; } string account = scene.GetComponent <GateSessionKeyComponent>().Get(request.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } Player player = EntityFactory.Create <Player, string>(Game.Scene, account); scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession); response.PlayerId = player.Id; reply(); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); await ETTask.CompletedTask; }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } Player player = ComponentFactory.Create <Player, string>(account); Game.Scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; await session.AddComponent <ActorComponent, IEntityActorHandler>(new GateSessionEntityActorHandler()).AddLocation(); response.PlayerId = player.Id; reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { //通过key获取帐号 string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(request.Key); //获取不到则为异常 if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } //获取得到 //创建Plaeyr实体 传递account给它的Awake方法 Player player = ComponentFactory.Create <Player, string>(account); //添加到PlayerComponent进行缓存 key是实例Id 其Awake方法内部只是像单例模式将静态变量Instance指向了它自己 Game.Scene.GetComponent <PlayerComponent>().Add(player); //给会话实体添加SessionPlayerComponent 并且缓存Player session.AddComponent <SessionPlayerComponent>().Player = player; //添加一个邮箱MailBoxComponent 将MailboxType.GateSession邮箱类型 传递给Awake方法 内部进行缓存而已 session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); //将PlayerId返回给客户端 response.PlayerId = player.Id; reply(); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); await ETTask.CompletedTask; }
protected override async void Run(Session session, C2G_GateLogin message, Action <G2C_GateLogin> reply) { G2C_GateLogin response = new G2C_GateLogin(); try { long userId = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); //添加收取Actor消息组件 并且本地化一下 就是所有服务器都能向这个对象发 并添加一个消息拦截器 await session.AddComponent <MailBoxComponent, string>(ActorInterceptType.GateSession).AddLocation(); //通知GateUserComponent组件和用户服玩家上线 并获取User实体 User user = await Game.Scene.GetComponent <GateUserComponent>().UserOnLine(userId, session.Id); if (user == null) { response.Message = "用户信息查询不到"; reply(response); return; } //记录客户端session在User中 user.AddComponent <UserClientSessionComponent>().session = session; //给Session组件添加下线监听组件和添加User实体 session.AddComponent <SessionUserComponent>().user = user; //返回客户端User信息和 当前服务器时间 response.User = user; response.ServerTime = TimeTool.GetCurrenTimeStamp(); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
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++; }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); StartConfigComponent startComponent = Game.Scene.GetComponent <StartConfigComponent>(); GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>(); try { long uid = gateSessionKeyComponent.Get(message.Key); if (uid <= 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key驗證失敗!"; reply(response); return; } // 登入成功,刪除Gate的Key gateSessionKeyComponent.Remove(message.Key); int lobbyAppId = 0; var player = CacheHelper.GetFromCache <Player>(uid); if (player != null && player.lobbyAppId != 0) { lobbyAppId = player.lobbyAppId; } else { lobbyAppId = SessionHelper.GetLobbyIdRandomly(); } // 隨機連接到Lobby伺服器,並創建PlayerUnit實體 G2L_LobbyUnitCreate g2L_LobbyUnitCreate = new G2L_LobbyUnitCreate(); g2L_LobbyUnitCreate.Uid = uid; g2L_LobbyUnitCreate.GateSessionId = session.InstanceId; g2L_LobbyUnitCreate.GateAppId = (int)IdGenerater.AppId; g2L_LobbyUnitCreate.LobbyAppId = lobbyAppId; // 等候LobbyUnit單元創建完成,並且也同步Player到了Gate Session lobbySession = SessionHelper.GetLobbySession(g2L_LobbyUnitCreate.LobbyAppId); L2G_LobbyUnitCreate l2G_LobbyUnitCreate = (L2G_LobbyUnitCreate)await lobbySession.Call(g2L_LobbyUnitCreate); if (l2G_LobbyUnitCreate.Error != ErrorCode.ERR_Success) { response.Error = l2G_LobbyUnitCreate.Error; reply(response); return; } player = BsonSerializer.Deserialize <Player>(l2G_LobbyUnitCreate.Json); CacheExHelper.WriteInCache(player, out player); session.AddComponent <SessionPlayerComponent, long>(player.gateSessionActorId).Player = player; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { PokerGateSessionKeyCpt pokerGateSessionKey = Game.Scene.GetComponent <PokerGateSessionKeyCpt>(); long key = pokerGateSessionKey.Get(message.Key); if (key == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "登录网关服务器失败。"; reply(response); return; } pokerGateSessionKey.Remove(message.Key); DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ETModel.UserInfo userInfo = await dbProxyComponent.Query <ETModel.UserInfo>(message.UserId); userInfo.GetComponent <UnitGateComponent>().GateSessionActorId = session.Id; if (session.GetComponent <SessionUserComponent>() == null) { session.AddComponent <SessionUserComponent>().userInfo = userInfo; } session.GetComponent <SessionUserComponent>().sessionId = session.Id; await session.AddComponent <MailBoxComponent, string>(ActorInterceptType.GateSession).AddLocation(); 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 G2R_PlayerOnline_Req() { UserID = message.UserId, GateAppID = config.StartConfig.AppId }); Game.Scene.GetComponent <PlayerManagerComponent>().Add(message.UserId, session.GetComponent <SessionUserComponent>(), session.Id); userInfo.IsOnline = true; await dbProxyComponent.Save(userInfo); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(Session session, A0003_LoginGate_C2G message, Action <A0003_LoginGate_G2C> reply) { A0003_LoginGate_G2C response = new A0003_LoginGate_G2C(); try { SessionKeyComponent GateSessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>(); //获取玩家的永久Id long userId = GateSessionKeyComponent.Get(message.GateLoginKey); //验证登录Key是否正确 if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; //客户端提示:连接网关服务器超时 reply(response); return; } //Key过期 GateSessionKeyComponent.Remove(message.GateLoginKey); //参数userId是数据库中的永久Id User user = ComponentFactory.Create <User, long>(userId); //将新上线的User添加到容器中 Game.Scene.GetComponent <UserComponent>().Add(user); user.AddComponent <MailBoxComponent>(); session.AddComponent <SessionUserComponent>().User = user; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); //回复Realm服务器 玩家已上线 GateAppID帮助Realm服务器定位玩家的位置 StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint; Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint); //2个参数 1:永久UserID 2:GateAppID realmSession.Send(new A0004_PlayerOnline_G2R() { UserID = user.UserID, GateAppID = config.StartConfig.AppId }); //设置User的参数 user.SelfGateAppID = config.StartConfig.AppId; user.SelfGateSessionID = session.InstanceId; user.ActorIDforClient = 0; //回复客户端 response.UserID = user.UserID; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(request.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } Player player = ComponentFactory.Create <Player, string>(account); Game.Scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); await ETTask.CompletedTask; // todo测试数据库连接 Log.Error("test access db"); //获取数据库 DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); //查询账号为admin List <ComponentWithId> users = await dbProxy.Query <UserInfo>(user => user.Account == "admin"); //列表大于0则为查询到 if (users.Count > 0) { //取得该条数据 UserInfo info = await dbProxy.Query <UserInfo>(users[0].Id); //修改改条数据的密码为2 info.PassWord = "******"; //更新数据 await dbProxy.Save(info); } //表达式删除所有账号为c的数据 await dbProxy.DeleteAll <UserInfo>(user => user.Account == "c"); //写入一条新数据 在ET中写入一条新数据的话需要使用此种方法来写入,否则的话_id 一直为0 会覆盖 UserInfo newdata = ComponentFactory.Create <UserInfo>(); newdata.Account = "user"; newdata.PassWord = "******"; await dbProxy.Save(newdata); }
protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>(); //从已经分发的KEY里面寻找,如果没找到,说明非法用户,不给他连接gate服务器 long playerID = gateSessionKeyComponent.Get(request.Key); if (playerID == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } //Key失效 gateSessionKeyComponent.Remove(request.Key); //专门给这个玩家创建一个Player对象 Player player = ComponentFactory.Create <Player, long>(playerID); player.AddComponent <UnitGateComponent, long>(session.InstanceId); //注册到PlayerComponent,方便管理 Game.Scene.GetComponent <PlayerComponent>().Add(player); //给这个session安排上Player session.AddComponent <SessionPlayerComponent>().Player = player; // 增加掉线组件 session.AddComponent <SessionOfflineComponent>(); // 增加心跳包 session.AddComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds(); //添加邮箱组件表示该session是一个Actor,接收的消息将会队列处理 await session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession).AddLocation(); Log.Info($"gate的actorid为{session.Id}"); //向登录服务器发送玩家上线消息 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 G2R_PlayerOnline() { PlayerIDInPlayerComponent = player.Id, PlayerId = player.PlayerID, GateAppID = config.StartConfig.AppId }); //Log.Info("发送离线消息完毕"); //回复客户端的连接gate服务器请求 reply(); await ETTask.CompletedTask; }
protected override async ETTask Run(Session session, A0003_LoginGate_C2G request, A0003_LoginGate_G2C response, Action reply) { try { SessionKeyComponent SessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>(); //获取玩家的永久Id long gateUserID = SessionKeyComponent.Get(request.GateLoginKey); //验证登录Key是否正确 if (gateUserID == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; //客户端提示:连接网关服务器超时 reply(); return; } //Key过期 SessionKeyComponent.Remove(request.GateLoginKey); //gateUserID传参创建User User user = ComponentFactory.Create <User, long>(gateUserID); //将新上线的User添加到UserComponent容器中 Game.Scene.GetComponent <UserComponent>().Add(user); user.AddComponent <MailBoxComponent>(); //session挂SessionUser组件,user绑定到session上 //session挂MailBox组件可以通过MailBox进行actor通信 session.AddComponent <SessionUserComponent>().User = user; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>(); //构建realmSession通知Realm服务器 玩家已上线 //... //设置User的参数 user.GateAppID = config.StartConfig.AppId; user.GateSessionID = session.InstanceId; user.ActorID = 0; //回复客户端 response.UserID = user.UserID; reply(); await ETTask.CompletedTask; } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>(); long userId = gateSessionKeyComponent.Get(message.Key); if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } //Key过期 gateSessionKeyComponent.Remove(message.Key); //创建User对象 User user = UserFactory.Create(userId, session.Id); await user.AddComponent <ActorComponent>().AddLocation(); //添加User对象关联到Session上 session.AddComponent <SessionUserComponent>().User = user; //添加消息转发组件 await session.AddComponent <ActorComponent, string>(ActorType.GateSession).AddLocation(); //向登录服务器发送玩家上线消息 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 G2R_PlayerOnline() { UserId = userId, GateAppId = config.StartConfig.AppId }); response.PlayerId = user.Id; response.UserId = user.UserID; reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { GameGateSessionKeyComponent landlordsGateSessionKeyComponent = Game.Scene.GetComponent <GameGateSessionKeyComponent>(); long userId = landlordsGateSessionKeyComponent.Get(message.Key); //验证登录Key是否正确 if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; reply(response); return; } //Key过期 landlordsGateSessionKeyComponent.Remove(message.Key); //创建User对象 User user = UserFactory.Create(userId, session.Id); await user.AddComponent <MailBoxComponent>().AddLocation(); //添加User对象关联到Session上 session.AddComponent <SessionUserComponent>().User = user; //session.AddComponent<HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds(); //添加消息转发组件 await session.AddComponent <MailBoxComponent, string>(ActorType.GateSession).AddLocation(); //向登录服务器发送玩家上线消息 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 G2R_PlayerOnline_Req() { UserID = userId, GateAppID = config.StartConfig.AppId }); response.PlayerID = user.Id; response.UserID = user.UserID; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_RBLoginGate message, Action <G2C_RBLoginGate> reply) { G2C_RBLoginGate response = new G2C_RBLoginGate(); try { Log.Debug("[C2G_LoginGate]key:" + message.Key); GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>(); long userId = gateSessionKeyComponent.Get(message.Key); if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; reply(response); return; } //Key过期 gateSessionKeyComponent.Remove(message.Key); //创建User对象 User user = ComponentFactory.Create <User, long>(userId); user.AddComponent <UnitGateComponent, long>(session.Id); Game.Scene.GetComponent <UserComponent>().Add(user); await user.AddComponent <MailBoxComponent>().AddLocation(); //添加User对象关联到Session上 session.AddComponent <SessionUserComponent>().User = user; //添加消息转发组件 await session.AddComponent <MailBoxComponent, string>(ActorType.GateSession).AddLocation(); //向登录服务器发送玩家上线消息 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 G2R_PlayerOnline() { UserID = userId, GateAppID = config.StartConfig.AppId }); response.PlayerId = user.Id; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { //获取key string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } //创建玩家 Player player = ComponentFactory.Create <Player, string>(account); //放到Player组件中 Game.Scene.GetComponent <PlayerComponent>().Add(player); //会话存放玩家 session.AddComponent <SessionPlayerComponent>().Player = player; //因为服务器负载均衡,并不知到具体在哪一个服务器,但服务器是明确的知道客户端的ip和端口号的 //模仿erlang的actor通信机制,实现跨进程的通信(实现原理:有一个位置服务器) //收信件的功能 session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(response); //发送一个登录成功的消息 session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
public override async ETTask C2G_LoginGateHandler(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { Console.WriteLine("C2G_LoginGateHandler"); Scene scene = Game.Scene.Get(request.GateId); if (scene == null) { return; } string account = scene.GetComponent <GateSessionKeyComponent>().Get(request.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } var results = await DBComponent.Instance.Query <Player>(x => x.Account == account); Player player = null; if (results.Count > 0) { player = results[0]; } else { player = EntityFactory.Create <Player, string>(Game.Scene, account); DBComponent.Instance.Save(player).Coroutine(); } scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession); response.PlayerId = player.Id; reply(); //session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); await ETTask.CompletedTask; }
private async ETVoid RunAsync(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { UInt64 account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } UserDB userDb = await GetUserDB(account); //Player player = ComponentFactory.Create<Player, string>(account); Player player = ComponentFactory.Create <Player, Session, UserDB>(session, userDb); player.Session = session; Game.Scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.PlayerId = player.Id; reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { /* * 动态key验证 */ string account = Game.Scene.GetComponent <GateSessionKeyComponent>().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } Player player = ComponentFactory.Create <Player, string>(account); Game.Scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, string>(ActorType.GateSession); response.PlayerId = player.Id; Console.WriteLine("userGate:"); reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_CowCowLoginGate message, Action <G2C_CowCowLoginGate> reply) { G2C_CowCowLoginGate response = new G2C_CowCowLoginGate(); try { CowCowGateSessionKeyComponent cowCowGateSessionKeyComponent = Game.Scene.GetComponent <CowCowGateSessionKeyComponent>(); long userId = cowCowGateSessionKeyComponent.Get(message.Key); //验证key if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; reply(response); return; } //从数据库拿用户数据用于大厅显示 UserInfo userInfo = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(userId); userInfo.AddComponent <UnitGateComponent, long>(session.InstanceId); //添加进用户信息管理组件,下线的时候保存并从组件中移除改用户信息 Game.Scene.GetComponent <UserInfoComponent>().Add(userInfo); //向登录服务器发送玩家上线消息 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 G2R_CowCowGamerOnline() { UserID = userId, GateAppID = config.StartConfig.AppId }); session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession); response.UserID = userInfo.Id; //永久ID,DB.Id response.NickName = userInfo.NickName; response.Diamond = userInfo.Diamond; response.Sex = userInfo.Sex; response.HeadIcon = userInfo.HeadIcon; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
private async ETVoid RunAsync(Session session, C2G_LandlordsLoginGate message, Action <G2C_LandlordsLoginGate> reply) { var respone = new G2C_LandlordsLoginGate(); try { var sessionKeyComponent = Game.Scene.GetComponent <LandlordsSessionKeyComponent>(); var userId = sessionKeyComponent.Get(message.Key); // 验证key是否有效 if (userId == 0) { respone.Error = ErrorCode.ERR_ConnectGateKeyError; reply(respone); return; } // 移除认证token sessionKeyComponent.Remove(message.Key); var user = ComponentFactory.Create <User, long>(userId); user.GateAppId = session.InstanceId; // 给用户增加MailBoxComponent,成为一个actor await user.AddComponent <MailBoxComponent>().AddLocation(); // 加入本gate服务器用户管理组件 Game.Scene.GetComponent <UserComponent>().Add(user); // 绑定session,在session销毁时会触发SessionUserComponent destroy事件 session.AddComponent <SessionUserComponent>().User = user; // 在线通知 var realmInnerIpEndPoint = StartConfigComponent.Instance.RealmConfig.GetComponent <InnerConfig>().IPEndPoint; var realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmInnerIpEndPoint); await realmSession.Call(new G2R_LandlordsOnline() { UserId = user.Id, GateAppId = user.GateAppId }); respone.PlayerId = user.InstanceId; reply(respone); } catch (Exception e) { ReplyError(respone, e, reply); } }
protected override void Run(Session session, R2G_GetLoginKey message, Action <G2R_GetLoginKey> reply) { G2R_GetLoginKey response = new G2R_GetLoginKey(); try { long key = RandomHelper.RandInt64(); Game.Scene.GetComponent <GateSessionKeyComponent>().Add(key, message.userId); response.Key = key; session.AddComponent <HeartTickComponent>().CurrentTime = TimeHelper.ClientNowSeconds(); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected async override void Run(Session session, C2S_UserLogin message, Action <S2C_UserLogin> reply) { S2C_UserLogin response = new S2C_UserLogin(); //直接创建一个unit Model.Fishs.Entitys.Unit unit = ComponentFactory.Create <Model.Fishs.Entitys.Unit, UnitType>(UnitType.Hero); unit.AddComponent <MailBoxComponent>(); unit.AddComponent <UnitGateComponent, long>(session.Id); unit.AddComponent <PlayerDbComponent, int>(message.AccountId); var initRet = await unit.GetComponent <PlayerDbComponent>().InitDataSync(); if (initRet) { Log.Debug("unitId:" + unit.Id); Game.Scene.GetComponent <UnitManageComponent>().Add(unit); } response.Tag = 0; Log.Debug("数据库结束:" + unit.Id); session.AddComponent <SessionPlayerComponent>().Player = unit; response.UnitId = unit.Id; reply(response); }
protected override async ETTask Run(Session session, C2G_Login request, G2C_Login response, Action reply) { Log.Info("玩家请求登录:" + request.Account + "玩家输入密码:" + request.Password); DBProxyComponent dBProxy = Game.Scene.GetComponent <DBProxyComponent>(); List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == request.Account); if (count.Count > 0) { if (count.Count == 1) { //取得该条数据 PlayerInfoDB info = await dBProxy.Query <PlayerInfoDB>(count[0].Id); //验证密码 if (info.pwd == request.Password) { Log.Info("密码正确,允许登录"); response.LoginFail = true; PlayerComponent playerComponent = Game.Scene.GetComponent <PlayerComponent>(); Player loginPlayer; //查看玩家是否已经登录创建过 if (playerComponent.AccountHaveBeCreated(request.Account)) { Log.Info("玩家被顶号: " + request.Account); //获取之前已经创建好的Player实体 loginPlayer = playerComponent.getPlayerByAccount(request.Account); try { //给被顶号的人发送被顶号的信息 loginPlayer.session.Send(new G2C_PlayerBackLogin() { NetMessage = "此账号在其它地方被登录" }); } catch { Log.Info("发送顶号信息失败:" + request.Account); } //给其它玩家广播这个玩家掉线的信息 playerComponent.PlayerBackLogin(request.Account).Coroutine(); } else { //创建登录玩家的实体 loginPlayer = PlayerFactory.Create(request.Account); //向玩家管理组件里添加玩家的信息 playerComponent.addPlayerToDict(request.Account, loginPlayer); } //对玩家的session进行记录 loginPlayer.session = session; session.AddComponent <SessionPlayerComponent>().Player = loginPlayer; } else { Log.Info("密码错误"); response.LoginFail = false; } } else { Log.Error("账号重复了: " + count.Count); response.LoginFail = false; } } else { response.LoginFail = false; } reply(); await ETTask.CompletedTask; }
protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply) { G2C_LoginGate response = new G2C_LoginGate(); try { long userId = Game.Scene.GetComponent <NjmjGateSessionKeyComponent>().Get(message.Key); if (userId == 0) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } // 检测是否已存在 UserComponentSystem.CheckIsExistTheUser(userId); //创建User对象 User user = UserFactory.Create(userId, session); await user.AddComponent <MailBoxComponent>().AddLocation(); //添加心跳包 session.AddComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds(); //添加User对象关联到Session上 session.AddComponent <SessionUserComponent>().User = user; //添加消息转发组件 session.AddComponent <MailBoxComponent, string>(ActorType.GateSession); response.PlayerId = user.Id; response.Uid = userId; ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); { //商城 if (ShopData.getInstance().getDataList().Count == 0) { List <ShopConfig> shopList = new List <ShopConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ShopConfig)).Length + 1; ++i) { int id = 1000 + i; ShopConfig config = (ShopConfig)configCom.Get(typeof(ShopConfig), id); shopList.Add(config); } ShopData.getInstance().getDataList().AddRange(shopList); } //#region AddShopInfo List <ShopInfo> shopInfoList = new List <ShopInfo>(); for (int i = 0; i < ShopData.getInstance().getDataList().Count; ++i) { ShopConfig config = ShopData.getInstance().getDataList()[i]; ShopInfo info = new ShopInfo(); info.Id = (int)config.Id; info.Name = config.Name; info.Price = config.Price; info.ShopType = config.shopType; info.Desc = config.Desc; info.CurrencyType = config.CurrencyType; info.Items = config.Items; info.Icon = config.Icon; info.VipPrice = config.VipPrice; shopInfoList.Add(info); } response.ShopInfoList = shopInfoList; } { //任务 if (TaskData.getInstance().getDataList().Count == 0) { List <TaskConfig> taskList = new List <TaskConfig>(); for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i) { int id = 100 + i; TaskConfig config = (TaskConfig)configCom.Get(typeof(TaskConfig), id); taskList.Add(config); } TaskData.getInstance().getDataList().AddRange(taskList); } } { //成就 if (ChengjiuData.getInstance().getDataList().Count == 0) { List <ChengjiuConfig> chengjiuList = new List <ChengjiuConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i) { int id = 100 + i; ChengjiuConfig config = (ChengjiuConfig)configCom.Get(typeof(ChengjiuConfig), id); chengjiuList.Add(config); } ChengjiuData.getInstance().getDataList().AddRange(chengjiuList); } } List <UserBag> bagInfoList = await proxyComponent.QueryJson <UserBag>($"{{UId:{userId}}}"); response.BagList = new List <Bag>(); List <Bag> bagList = new List <Bag>(); for (int i = 0; i < bagInfoList.Count; ++i) { Bag bag = new Bag(); bag.ItemId = bagInfoList[i].BagId; bag.Count = bagInfoList[i].Count; bagList.Add(bag); } response.BagList = bagList; PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(userId); // 老用户检测 { try { AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(userId); if (accountInfo.OldAccountState == 1) { string url = "http://fksq.hy51v.com:10086/CheckIsOldUser?machine_id=" + accountInfo.MachineId + "&game_id=217"; string str = HttpUtil.GetHttp(url); Log.Debug("web地址:" + url); Log.Debug("判断是否是老用户:" + str); JObject result = JObject.Parse(str); string old_uid = (string)result.GetValue("old_uid"); // 不是老用户 if (string.IsNullOrEmpty(old_uid)) { accountInfo.OldAccountState = 3; await proxyComponent.Save(accountInfo); } // 是老用户 else { List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}"); if (log_OldUserBinds.Count > 0) { accountInfo.OldAccountState = 3; await proxyComponent.Save(accountInfo); } else { accountInfo.OldAccountState = 2; await proxyComponent.Save(accountInfo); // 记录绑定日志 { Log_OldUserBind log_OldUserBind = ComponentFactory.CreateWithId <Log_OldUserBind>(IdGenerater.GenerateId()); log_OldUserBind.Uid = userId; log_OldUserBind.OldUid = old_uid; log_OldUserBind.macId = accountInfo.MachineId; log_OldUserBind.isSendReward = 1; await proxyComponent.Save(log_OldUserBind); } { url = ("http://fksq.hy51v.com:10086/GetOldNjmjData?UserId=" + old_uid); str = HttpUtil.GetHttp(url); result = JObject.Parse(str); int moneyAmount = (int)result.GetValue("moneyAmount"); int gIngotAmount = (int)result.GetValue("gIngotAmount"); Log.Debug("老用户金币=" + moneyAmount + " 元宝=" + gIngotAmount); playerBaseInfo.GoldNum = moneyAmount; playerBaseInfo.WingNum = gIngotAmount; await proxyComponent.Save(playerBaseInfo); await DBCommonUtil.changeWealthWithStr(userId, "111:10;2:10", "老用户赠送"); } // 发送老用户广播 Actor_OldUser actor_OldUser = new Actor_OldUser(); actor_OldUser.OldAccount = old_uid; Game.Scene.GetComponent <UserComponent>().BroadCastToSingle(actor_OldUser, userId); } } } else if (accountInfo.OldAccountState == 2) { List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}"); if (log_OldUserBinds.Count > 0) { if (log_OldUserBinds[0].isSendReward != 1) { log_OldUserBinds[0].isSendReward = 1; await proxyComponent.Save(log_OldUserBinds[0]); await DBCommonUtil.SendMail(userId, "更新游戏奖励", "亲爱的玩家,南京麻将最新版本更新了,特意送上更新奖励,请笑纳,祝您游戏愉快!", "111:10;2:10"); } } } } catch (Exception ex) { Log.Error("检测是否是老用户出错:" + ex); } } #region 用户活动所获得的头像数据 List <OtherData> otherDatas = await proxyComponent.QueryJson <OtherData>($"{{UId:{userId}}}"); if (otherDatas.Count > 0) { response.ownIcon = otherDatas[0].OwnIcon; } #endregion reply(response); session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); // vip上线全服广播 { if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { Actor_LaBa actor_LaBa = new Actor_LaBa(); actor_LaBa.LaBaContent = "贵族玩家" + playerBaseInfo.Name + "上线啦!"; Game.Scene.GetComponent <UserComponent>().BroadCast(actor_LaBa); } } } catch (Exception e) { ReplyError(response, e, reply); } }