コード例 #1
0
        public async Task <bool> OnHandle(MessageContext context, CCreateNickReqMessage message)
        {
            var session = (Session)context.Session;
            var logger  = _logger.ForContext(
                ("RemoteEndPoint", session.RemoteEndPoint.ToString()),
                ("Nickname", message.Nickname));

            var available = await IsNickAvailableAsync(message.Nickname);

            if (!available)
            {
                logger.Debug("Nickname not available");
                session.Send(new SCheckNickAckMessage(true));
            }

            session.Player.Account.Nickname = message.Nickname;
            using (var db = _databaseService.Open <AuthContext>())
            {
                var accountId = (long)session.Player.Account.Id;
                await db.Accounts
                .Where(x => x.Id == accountId)
                .UpdateAsync(x => new AccountEntity {
                    Nickname = message.Nickname
                });
            }

            session.Send(new SServerResultInfoAckMessage(ServerResult.CreateNicknameSuccess));
            await session.Player.SendAccountInformation();

            session.Player.OnNicknameCreated(message.Nickname);
            return(true);
        }
コード例 #2
0
        public async Task CreateNickHandler(GameServer server, GameSession session, CCreateNickReqMessage message)
        {
            if (session.Player == null || !string.IsNullOrWhiteSpace(session.Player.Account.Nickname))
            {
                session.Dispose();
                return;
            }

            Logger.Info()
            .Account(session)
            .Message("Creating nickname {0}", message.Nickname)
            .Write();

            if (!await IsNickAvailableAsync(message.Nickname).ConfigureAwait(false))
            {
                Logger.Error()
                .Account(session)
                .Message("Nickname not available: {0}", message.Nickname)
                .Write();

                await session.SendAsync(new SCheckNickAckMessage(false))
                .ConfigureAwait(false);

                return;
            }

            session.Player.Account.Nickname = message.Nickname;
            using (var scope = new DataAccessScope())
            {
                var accountDto = AuthDatabase.Instance.Accounts.GetReference((int)session.Player.Account.Id);
                //if (accountDto == null)
                //{
                //    Logger.Error()
                //        .Account(session)
                //        .Message("Account {0} not found", session.Player.Account.Id)
                //        .Write();

                //    await session.SendAsync(new SCheckNickAckMessage(false))
                //        .ConfigureAwait(false);
                //    return;
                //}
                accountDto.Nickname = message.Nickname;

                await scope.CompleteAsync()
                .ConfigureAwait(false);
            }
            //session.Send(new SCreateNickAckMessage { Nickname = msg.Nickname });
            await session.SendAsync(new SServerResultInfoAckMessage(ServerResult.CreateNicknameSuccess))
            .ConfigureAwait(false);

            Logger.Info()
            .Account(session)
            .Message("Created nickname {0}", message.Nickname)
            .Write();

            await LoginAsync(server, session)
            .ConfigureAwait(false);
        }
コード例 #3
0
        public async Task CreateNickHandler(GameServer server, GameSession session, CCreateNickReqMessage message)
        {
            if (session.Player == null || !string.IsNullOrWhiteSpace(session.Player.Account.Nickname))
            {
                session.Dispose();
                return;
            }

            Logger.Info()
            .Account(session)
            .Message($"Creating nickname {message.Nickname}")
            .Write();

            if (!await IsNickAvailableAsync(message.Nickname).ConfigureAwait(false))
            {
                Logger.Error()
                .Account(session)
                .Message($"Nickname not available: {message.Nickname}")
                .Write();

                await session.SendAsync(new SCheckNickAckMessage(false))
                .ConfigureAwait(false);

                return;
            }

            session.Player.Account.Nickname = message.Nickname;
            using (var db = AuthDatabase.Open())
            {
                var mapping = OrmConfiguration
                              .GetDefaultEntityMapping <AccountDto>()
                              .Clone()
                              .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, nameof(AccountDto.Nickname));

                await db.UpdateAsync(new AccountDto { Id = (int)session.Player.Account.Id, Nickname = message.Nickname },
                                     statement => statement.WithEntityMappingOverride(mapping))
                .ConfigureAwait(false);
            }
            //session.Send(new SCreateNickAckMessage { Nickname = msg.Nickname });
            await session.SendAsync(new SServerResultInfoAckMessage(ServerResult.CreateNicknameSuccess))
            .ConfigureAwait(false);

            Logger.Info()
            .Account(session)
            .Message($"Created nickname {message.Nickname}")
            .Write();

            await LoginAsync(server, session)
            .ConfigureAwait(false);
        }