Example #1
0
        protected override void HandleVoltronSessionResponse(IAriesSession session, object message)
        {
            var rawSession = (AriesSession)session;
            var packet     = message as RequestClientSessionResponse;

            if (message != null)
            {
                DbLotServerTicket ticket = null;

                using (var da = DAFactory.Get())
                {
                    ticket = da.Lots.GetLotServerTicket(packet.Password);
                    if (ticket != null)
                    {
                        //TODO: Check if its expired
                        da.Lots.DeleteLotServerTicket(packet.Password);
                    }


                    if (ticket != null)
                    {
                        uint location = 0;
                        if ((ticket.lot_id & 0x40000000) > 0)
                        {
                            location = (uint)ticket.lot_id;
                        }
                        else
                        {
                            location = da.Lots.Get(ticket.lot_id).location;
                        }

                        //We need to claim a lock for the avatar, if we can't do that we cant let them join
                        var didClaim = da.AvatarClaims.Claim(ticket.avatar_claim_id, ticket.avatar_claim_owner, Config.Call_Sign, location);
                        if (!didClaim)
                        {
                            rawSession.Close();
                            return;
                        }


                        //Time to upgrade to a voltron session
                        var newSession = Sessions.UpgradeSession <VoltronSession>(rawSession, x =>
                        {
                            x.UserId          = ticket.user_id;
                            x.AvatarId        = ticket.avatar_id;
                            x.IsAuthenticated = true;
                            x.AvatarClaimId   = ticket.avatar_claim_id;
                        });

                        newSession.SetAttribute("cityCallSign", ticket.avatar_claim_owner);

                        //Try and join the lot, no reason to keep this connection alive if you can't get in
                        if (!Lots.TryJoin(ticket.lot_id, newSession))
                        {
                            newSession.Close();
                            using (var db = DAFactory.Get())
                            {
                                //return claim to the city we got it from.
                                db.AvatarClaims.Claim(newSession.AvatarClaimId, Config.Call_Sign, (string)newSession.GetAttribute("cityCallSign"), 0);
                            }
                        }
                        return;
                    }
                }
            }

            //Failed authentication
            rawSession.Close();
        }
Example #2
0
        protected override void HandleVoltronSessionResponse(IAriesSession session, object message)
        {
            var rawSession = (AriesSession)session;
            var packet     = message as RequestClientSessionResponse;

            if (message != null)
            {
                using (var da = DAFactory.Get())
                {
                    var ticket = da.Shards.GetTicket(packet.Password);
                    if (ticket != null)
                    {
                        //TODO: Check if its expired
                        da.Shards.DeleteTicket(packet.Password);

                        int?claim = 0;
                        //We need to lock this avatar
                        if (ticket.avatar_id != 0) //if is 0, we're "anonymous", which limits what we can do to basically only CAS.
                        {
                            claim = da.AvatarClaims.TryCreate(new DbAvatarClaim
                            {
                                avatar_id = ticket.avatar_id,
                                location  = 0,
                                owner     = Config.Call_Sign
                            });

                            if (!claim.HasValue)
                            {
                                //Try and disconnect this user, if we still can't get a claim out of luck
                                //The voltron session close should handle removing any lot tickets and disconnecting them from the target servers
                                //then it will remove the avatar claim. This takes time but it should be less than 5 seconds.
                                var existingSession = Sessions.GetByAvatarId(ticket.avatar_id);
                                if (existingSession != null)
                                {
                                    existingSession.Close();
                                }
                                else
                                {
                                    //check if there really is an old claim
                                    var oldClaim = da.AvatarClaims.GetByAvatarID(ticket.avatar_id);
                                    if (oldClaim != null)
                                    {
                                        da.AvatarClaims.Delete(oldClaim.avatar_claim_id, Config.Call_Sign);
                                        LOG.Debug("Zombie Avatar claim removed: Avatar ID " + ticket.avatar_id);
                                    }
                                    else
                                    {
                                        LOG.Debug("Unknown claim error occurred. Connection will likely time out. Avatar ID " + ticket.avatar_id);
                                    }
                                }

                                //TODO: Broadcast to lot servers to disconnect

                                int i = 0;
                                while (i < 10)
                                {
                                    claim = da.AvatarClaims.TryCreate(new DbAvatarClaim
                                    {
                                        avatar_id = ticket.avatar_id,
                                        location  = 0,
                                        owner     = Config.Call_Sign
                                    });

                                    if (claim.HasValue)
                                    {
                                        break;
                                    }

                                    Thread.Sleep(500);
                                    i++;
                                }

                                if (!claim.HasValue)
                                {
                                    //No luck
                                    session.Close();
                                    return;
                                }
                            }
                        }

                        //Time to upgrade to a voltron session
                        var newSession = Sessions.UpgradeSession <VoltronSession>(rawSession, x => {
                            x.UserId          = ticket.user_id;
                            x.AvatarId        = ticket.avatar_id;
                            x.IsAuthenticated = true;
                            x.AvatarClaimId   = claim.Value;
                        });
                        return;
                    }
                }
            }

            //Failed authentication
            rawSession.Close();
        }