protected override async void Run(Session session, C2R_Register_Req message, Action <R2C_Register_Res> reply) { R2C_Register_Res response = new R2C_Register_Res(); try { DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account); if (result.Count > 0) { response.Error = ErrorCode.ERR_AccountAlreadyRegister; response.Message = "当前账号已经被注册 !!!"; reply(response); return; } AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(IdGenerater.GenerateId()); newAccount.Account = message.Account; newAccount.Password = message.Password; Log.Info($"注册新账号:{MongoHelper.ToJson(newAccount)}"); ETModel.UserInfo newUser = UserInfoFactory.Create(newAccount.Id, session); if (newUser.GetComponent <MailBoxComponent>() != null) { newUser.RemoveComponent <MailBoxComponent>(); } await newUser.AddComponent <MailBoxComponent>().AddLocation(); newUser.PlayerId = RandomHelper.GenerateRandomPlayerId(6); newUser.Account = message.Account; newUser.Nickname = $"{ RandomHelper.GenerateRandomCode(4):0000}"; newUser.HeadId = RandomHelper.GetRandom().Next(1, 11); if (newUser.HeadId < 6) { newUser.Gender = 1; } else { newUser.Gender = 2; } newUser.Gold = 100000; newUser.IsTourist = false; await dbProxy.Save(newAccount); await dbProxy.Save(newUser); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_TouristsLogin_Req message, Action <G2C_TouristsLogin_Res> reply) { G2C_TouristsLogin_Res response = new G2C_TouristsLogin_Res(); try { AccountInfo newAccount = ComponentFactory.CreateWithId <AccountInfo>(IdGenerater.GenerateId()); newAccount.Account = GetRandomString(6); newAccount.Password = MakePassword(6); DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == newAccount.Account); if (result.Count > 0) { newAccount.Account += RandomHelper.GetRandom().Next(0, 9); } ETModel.UserInfo newUser = UserInfoFactory.Create(newAccount.Id, session); newUser.PlayerId = RandomHelper.GenerateRandomCode(6); newUser.Account = newAccount.Account; newUser.Nickname = $"游客{ RandomHelper.GenerateRandomCode(4):0000}"; newUser.HeadId = RandomHelper.GetRandom().Next(1, 11); if (newUser.HeadId < 6) { newUser.Gender = 1; } else { newUser.Gender = 2; } newUser.Gold = 0; newUser.IsTourist = true; await dbProxy.Save(newAccount); await dbProxy.Save(newUser); response.Account = newAccount.Account; response.Password = newAccount.Password; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }