예제 #1
0
        public async Task Init(string characterName)
        {
            if (ConnectionList.TryGetValue(UserName, out var details))
            {
                await details.ClientProxy.SendAsync("DisconnectDuplicateConnection");

                var startWait = DateTime.Now;
                while (ConnectionList.ContainsKey(UserName))
                {
                    await Task.Delay(100);

                    if (DateTime.Now > startWait.AddSeconds(3))
                    {
                        await Clients.Caller.SendAsync("FailLoginDueToExistingConnection");

                        return;
                    }
                }
            }
            var characterID = DataService.GetCharacter(UserName, characterName).ID;

            GameEngine.Current.InputQueue.Enqueue(dbContext =>
            {
                var character           = dbContext.PlayerCharacters.Find(characterID);
                character.MovementAngle = 0;
                character.MovementForce = 0;
            });
            ConnectionDetails = new ConnectionDetails()
            {
                CharacterName = characterName,
                CharacterID   = characterID,
                UserName      = UserName,
                ConnectionID  = Context.ConnectionId,
                ClientProxy   = Clients.Caller
            };
            SendInitialUpdate();

            ConnectionList.AddOrUpdate(UserName, ConnectionDetails, (k, v) => ConnectionDetails);
            await Clients.All.SendAsync("CharacterConnected", characterName);
        }