Exemplo n.º 1
0
 public void UserJoined(IVoltronSession session)
 {
     //common info used by most requests
     using (var da = DAFactory.Get())
     {
         var myLotID = da.Roommates.GetAvatarsLots(session.AvatarId).FirstOrDefault();
         var myLot   = (myLotID == null) ? null : da.Lots.Get(myLotID.lot_id);
         if (myLot != null)
         {
             var myNeigh = da.Neighborhoods.Get(myLot.neighborhood_id);
             if (myNeigh != null && myNeigh.election_cycle_id != null)
             {
                 var curCycle = da.Elections.GetCycle(myNeigh.election_cycle_id.Value);
                 if (curCycle != null)
                 {
                     var date = Epoch.Now;
                     if (StateHasEmail(curCycle.current_state) && date < curCycle.end_date + 3 * 24 * 60 * 60)
                     {
                         var mail = Kernel.Get <MailHandler>();
                         SendStateEmail(da, mail, myNeigh, curCycle, session.AvatarId);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public async void SessionUpgraded(IAriesSession oldSession, IAriesSession newSession)
        {
            if (!(newSession is IVoltronSession))
            {
                return;
            }

            //Aries session has upgraded to a voltron session
            IVoltronSession voltronSession = (IVoltronSession)newSession;

            //TODO: Make sure this user is not already connected, if they are disconnect them
            newSession.Write(new HostOnlinePDU
            {
                ClientBufSize     = 4096,
                HostVersion       = 0x7FFF,
                HostReservedWords = 0
            });

            //CAS, don't hydrate the user
            if (voltronSession.IsAnonymous)
            {
                return;
            }

            //New avatar, enroll in voltron group
            var avatar = await DataService.Get <Avatar>(voltronSession.AvatarId);

            //Mark as online
            avatar.Avatar_IsOnline = true;
            VoltronSessions.Enroll(newSession);

            //TODO: Somehow alert people this sim is online?
        }
Exemplo n.º 3
0
        public bool TryJoin(IVoltronSession session)
        {
            if (Container.IsAvatarOnLot(session.AvatarId))
            {
                return(false);                                           //already on the lot.
            }
            lock (_Visitors)
            {
                if (ShuttingDown || (_Visitors.Count >= ((Context.HighMax)?128:24)))
                {
                    if (ShuttingDown)
                    {
                        return(false);              //cannot join
                    }
                    //check if this user has special permissions. should only happen when a lot is full
                    //let them in anyways if they do
                    var avatar = DAFactory.Get().Avatars.Get(session.AvatarId);
                    if (avatar.moderation_level == 0 && !Context.JobLot)
                    {
                        if (DAFactory.Get().Roommates.Get(session.AvatarId, Context.DbId) == null)
                        {
                            return(false); //not a roommate
                        }
                    }
                }

                session.SetAttribute("currentLot", ((Context.Id & 0x40000000) > 0)?(int)Context.Id:Context.DbId);
                _Visitors.Add(session.AvatarId, session);

                SyncNumVisitors();

                InBackground(() => Container.AvatarJoin(session));
                return(true);
            }
        }
Exemplo n.º 4
0
        public void Handle(IVoltronSession session, FindAvatarRequest packet)
        {
            if (session.IsAnonymous)
            {
                return;
            }
            using (var da = DAFactory.Get()) {
                var privacy = da.Avatars.GetPrivacyMode(packet.AvatarId);
                if (privacy > 0)
                {
                    session.Write(new FindAvatarResponse
                    {
                        AvatarId = packet.AvatarId,
                        LotId    = 0,
                        Status   = FindAvatarResponseStatus.PRIVACY_ENABLED
                    });
                    return;
                }
                //TODO: get ignore status

                var claim = da.AvatarClaims.GetByAvatarID(packet.AvatarId);
                //maybe check shard id against avatar in future. The client should do this anyways, and the server providing this functionality to everyone isnt a disaster.
                var location = claim?.location ?? 0;
                session.Write(new FindAvatarResponse
                {
                    AvatarId = packet.AvatarId,
                    LotId    = location,
                    Status   = (location == 0)?FindAvatarResponseStatus.NOT_ON_LOT:FindAvatarResponseStatus.FOUND
                });
            }
        }
Exemplo n.º 5
0
        public void UserJoined(IVoltronSession session)
        {
            using (var da = DAFactory.Get())
            {
                var myLotID = da.Roommates.GetAvatarsLots(session.AvatarId).FirstOrDefault();
                var myLot   = (myLotID == null) ? null : da.Lots.Get(myLotID.lot_id);
                if (myLot != null)
                {
                    var free    = da.Elections.GetFreeVote(session.AvatarId);
                    var nhoodID = (int)(myLot?.neighborhood_id ?? 0);
                    if (free != null)
                    {
                        nhoodID = free.neighborhood_id; //enrolled to a free vote. receive vote mail for that neighborhood
                    }

                    var myNeigh = da.Neighborhoods.Get((uint)nhoodID);
                    if (myNeigh != null && myNeigh.election_cycle_id != null)
                    {
                        var curCycle = da.Elections.GetCycle(myNeigh.election_cycle_id.Value);
                        if (curCycle != null)
                        {
                            var date = Epoch.Now;
                            if (StateHasEmail(curCycle.current_state) && date < curCycle.end_date + 3 * 24 * 60 * 60)
                            {
                                var mail = Kernel.Get <MailHandler>();
                                SendStateEmail(da, mail, myNeigh, curCycle, session.AvatarId);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
 public void Handle(IVoltronSession session, DBRequestWrapperPDU packet)
 {
     if (packet.Body is cTSONetMessageStandard)
     {
         HandleNetMessage(session, (cTSONetMessageStandard)packet.Body, packet);
     }
 }
Exemplo n.º 7
0
 public void Message(IVoltronSession session, object message)
 {
     if (message is FSOVMCommand)
     {
         Container.Message(session, (FSOVMCommand)message);
     }
 }
Exemplo n.º 8
0
 public void Refresh(IVoltronSession session)
 {
     lock (_Visitors)
     {
         InBackground(() => Container.AvatarRefresh(session));
     }
 }
Exemplo n.º 9
0
 public void Handle(IVoltronSession session, FindPlayerPDU packet)
 {
     session.Write(new FindPlayerResponsePDU {
         StatusCode = 0x00,
         ReasonText = "uh"
     });
 }
Exemplo n.º 10
0
 public void Leave(IVoltronSession session)
 {
     lock (_Visitors)
     {
         InBackground(() => Container.AvatarLeave(session));
     }
 }
Exemplo n.º 11
0
        public async void Handle(IVoltronSession session, AvatarRetireRequest packet)
        {
            if (session.IsAnonymous) //CAS users can't do this.
            {
                return;
            }

            try
            {
                using (var da = DA.Get)
                {
                    var avatar = da.Avatars.Get(session.AvatarId);
                    if (avatar == null)
                    {
                        return;
                    }

                    if (avatar.date > Epoch.Now - (60 * 60 * 24 * 7) && !da.Users.GetById(session.UserId).is_admin)
                    {
                        session.Write(new Protocol.Voltron.Packets.AnnouncementMsgPDU()
                        {
                            SenderID = "??" + "System",
                            Message  = "\r\n" + "You cannot delete a sim younger than a week old!",
                            Subject  = "Error"
                        });
                        LOG.Info("Avatar " + avatar.name + " under account " + avatar.user_id + " attempted to delete a less than week old account.");

                        session.Close();
                        return;
                    }
                    LOG.Info("Deleting avatar " + avatar.name + " under account " + avatar.user_id + ".");

                    var lots = da.Roommates.GetAvatarsLots(session.AvatarId);
                    foreach (var roomie in lots)
                    {
                        var lot = da.Lots.Get(roomie.lot_id);
                        if (lot == null)
                        {
                            continue;
                        }
                        var kickResult = await Kernel.Get <ChangeRoommateHandler>().TryKick(lot.location, session.AvatarId, session.AvatarId);

                        //if something goes wrong here, just return.
                        if (kickResult != Protocol.Electron.Model.ChangeRoommateResponseStatus.SELFKICK_SUCCESS)
                        {
                            return;
                        }
                    }

                    da.Avatars.Delete(session.AvatarId);
                }

                //now all our objects have null owner. objects with null owner will be cleaned out by the purge task (this needs to hit nfs & db).

                session.Close();
            } catch
            {
            }
        }
Exemplo n.º 12
0
 public void Handle(IVoltronSession session, SetIgnoreListPDU packet)
 {
     session.Write(new SetIgnoreListResponsePDU {
         StatusCode         = 0,
         ReasonText         = "OK",
         MaxNumberOfIgnored = 50
     });
 }
Exemplo n.º 13
0
        public void SessionClosed(IVoltronSession session)
        {
            var lot = GetLot(session);

            if (lot != null)
            {
                lot.Leave(session);
            }
        }
Exemplo n.º 14
0
        public void RouteMessage(IVoltronSession session, object message)
        {
            var lot = GetLot(session);

            if (lot != null)
            {
                lot.Message(session, message);
            }
        }
Exemplo n.º 15
0
        public void SessionMigrated(IVoltronSession session)
        {
            var lot = GetLot(session);

            if (lot != null)
            {
                lot.Refresh(session);
            }
        }
Exemplo n.º 16
0
        public void UserJoinedEvent(IVoltronSession session, DbEvent evt, bool alreadyOnline)
        {
            try
            {
                var needsParticipation = evt.mail_message != null || ParticipationType(evt.type);
                if (!needsParticipation)
                {
                    return;
                }
                using (var db = DA.Get)
                {
                    var user          = session.UserId;
                    var participation = db.Events.TryParticipate(new DbEventParticipation()
                    {
                        event_id = evt.event_id, user_id = user
                    });
                    if (participation)
                    {
                        if (evt.mail_message != null)
                        {
                            Mail.SendEmail(new Files.Formats.tsodata.MessageItem()
                            {
                                Subject    = evt.mail_subject ?? "Event",
                                Body       = evt.mail_message,
                                SenderID   = (uint)(evt.mail_sender ?? (int.MinValue)),
                                SenderName = evt.mail_sender_name ?? "The Sims Online",
                                TargetID   = session.AvatarId,
                                Type       = 4,
                                Subtype    = 0
                            }, alreadyOnline);
                        }
                        switch (evt.type)
                        {
                        case DbEventType.free_object:
                            for (int i = 0; i < Math.Max(1, evt.value2); i++)
                            {
                                db.Objects.Create(new Database.DA.Objects.DbObject()
                                {
                                    type         = (uint)evt.value,
                                    shard_id     = Context.ShardId,
                                    owner_id     = session.AvatarId,
                                    lot_id       = null, //to inventory
                                    dyn_obj_name = ""
                                });
                            }
                            break;

                        case DbEventType.free_money:
                            db.Avatars.Transaction(uint.MaxValue, session.AvatarId, evt.value, 0);
                            break;
                        }
                    }
                }
            } catch
            {
            }
        }
        public async void SessionClosed(IAriesSession session)
        {
            if (!(session is IVoltronSession))
            {
                return;
            }

            IVoltronSession voltronSession = (IVoltronSession)session;

            VoltronSessions.UnEnroll(session);

            if (voltronSession.IsAnonymous)
            {
                return;
            }

            Liveness.EnqueueChange(() => {
                //unenroll in voltron group, mark as offline in data service.
                //since this can happen async make sure our session hasnt been reopened before trying to delete its claim
                if (Sessions.GetByAvatarId(voltronSession.AvatarId)?.Connected == true)
                {
                    return;
                }

                var avatar = DataService.Get <Avatar>(voltronSession.AvatarId).Result;
                if (avatar != null)
                {
                    avatar.Avatar_IsOnline = false;
                }

                using (var db = DAFactory.Get())
                {
                    // if we don't own the claim for the avatar, we need to tell the server that does to release the avatar.
                    // right now it's just lot servers.

                    var claim = db.AvatarClaims.Get(voltronSession.AvatarClaimId);
                    if (claim != null && claim.owner != Context.Config.Call_Sign)
                    {
                        var lotServer = LotServers.GetLotServerSession(claim.owner);
                        if (lotServer != null)
                        {
                            var lot = db.Lots.GetByLocation(Context.ShardId, claim.location);
                            lotServer.Write(new RequestLotClientTermination()
                            {
                                AvatarId  = voltronSession.AvatarId,
                                LotId     = (lot != null) ? lot.lot_id : ((int)claim.location),
                                FromOwner = Context.Config.Call_Sign
                            });
                        }
                    }

                    //nuke the claim anyways to be sure.
                    db.AvatarClaims.Delete(voltronSession.AvatarClaimId, Context.Config.Call_Sign);
                }
            });
        }
Exemplo n.º 18
0
        public void UserJoined(IVoltronSession session)
        {
            List <DbEvent> evts;

            lock (ActiveEvents) evts = new List <DbEvent>(ActiveEvents);
            foreach (var evt in evts)
            {
                UserJoinedEvent(session, evt, false);
            }
        }
Exemplo n.º 19
0
        public void ReleaseAvatarClaim(uint id)
        {
            IVoltronSession session = null;

            lock (_Visitors)
            {
                _Visitors.TryGetValue(id, out session);
            }
            ReleaseAvatarClaim(session);
        }
Exemplo n.º 20
0
        public void SessionMigrated(IAriesSession session)
        {
            if (!(session is IVoltronSession))
            {
                return;
            }
            IVoltronSession voltronSession = (IVoltronSession)session;

            Lots.SessionMigrated(voltronSession);
        }
Exemplo n.º 21
0
        public bool TryJoin(int lotId, IVoltronSession session)
        {
            var lot = GetLot(lotId);

            if (lot == null)
            {
                return(false);
            }

            return(lot.TryJoin(session));
        }
Exemplo n.º 22
0
        public async void SessionClosed(IAriesSession session)
        {
            if (!(session is IVoltronSession))
            {
                return;
            }

            IVoltronSession voltronSession = (IVoltronSession)session;

            Lots.SessionClosed(voltronSession);
        }
Exemplo n.º 23
0
 public void Send(uint avatarID, params object[] messages)
 {
     lock (_Visitors)
     {
         IVoltronSession visitor = null;
         if (_Visitors.TryGetValue(avatarID, out visitor))
         {
             visitor.Write(messages);
         }
     }
 }
Exemplo n.º 24
0
 public void UserJoined(IVoltronSession session)
 {
     if (TuningCache == null)
     {
         UpdateTuningCache();
     }
     session.Write(new GlobalTuningUpdate()
     {
         Tuning = TuningCache
     });
 }
Exemplo n.º 25
0
 public void UserJoined(IVoltronSession session)
 {
     if (TuningCache == null)
     {
         UpdateTuningCache();
     }
     session.Write(new GlobalTuningUpdate()
     {
         Tuning = TuningCache, ObjectUpgrades = ObjectUpgradeData
     });
 }
Exemplo n.º 26
0
        //Run on the background thread
        public void AvatarLeave(IVoltronSession session)
        {
            //Exit lot, Persist the avatars data, remove avatar lock
            LOG.Info("Avatar left");

            // defer the following so that the avatar save is queued, then their session's claim is released.
            lock (SessionsToRelease) SessionsToRelease.Add(session);

            VMDriver.DisconnectClient(session.AvatarId);
            ClientCount--;
        }
Exemplo n.º 27
0
        private object HandleSearchWildcard(IVoltronSession session, cTSONetMessageStandard msg)
        {
            var request = msg.ComplexParameter as SearchRequest;

            if (request == null)
            {
                return(null);
            }

            using (var db = DAFactory.Get())
            {
                List <SearchResponseItem> results = null;

                if (request.Type == SearchType.SIMS)
                {
                    results = db.Avatars.SearchWildcard(Context.ShardId, request.Query, 100).Select(x => new SearchResponseItem
                    {
                        Name     = x.name,
                        EntityId = x.avatar_id
                    }).ToList();
                }
                else if (request.Type == SearchType.NHOOD)
                {
                    results = db.Neighborhoods.SearchWildcard(Context.ShardId, request.Query, 100).Select(x => new SearchResponseItem
                    {
                        Name     = x.name,
                        EntityId = (uint)x.neighborhood_id
                    }).ToList();
                }
                else
                {
                    results = db.Lots.SearchWildcard(Context.ShardId, request.Query, 100).Select(x => new SearchResponseItem
                    {
                        Name     = x.name,
                        EntityId = x.location
                    }).ToList();
                }

                return(new cTSONetMessageStandard()
                {
                    MessageID = 0xDBF301A9,
                    DatabaseType = DBResponseType.Search.GetResponseID(),
                    Parameter = msg.Parameter,

                    ComplexParameter = new SearchResponse()
                    {
                        Query = request.Query,
                        Type = request.Type,
                        Items = results
                    }
                });
            }
        }
Exemplo n.º 28
0
 public void WriteFail(IVoltronSession session, InstantMessage message, InstantMessageFailureReason fail)
 {
     session.Write(new InstantMessage
     {
         FromType = FSO.Common.Enum.UserReferenceType.AVATAR,
         From     = message.To,
         Type     = InstantMessageType.FAILURE_ACK,
         Message  = "",
         AckID    = message.AckID,
         Reason   = fail
     });
 }
Exemplo n.º 29
0
        public void Handle(IVoltronSession session, ModerationRequest packet)
        {
            if (session.IsAnonymous)
            {
                return;
            }
            using (var da = DAFactory.Get)
            {
                var user  = da.Users.GetById(session.UserId);
                var mod   = user.is_moderator;
                var admin = user.is_admin;

                if (!(mod || admin))
                {
                    return;
                }

                switch (packet.Type)
                {
                case ModerationRequestType.IPBAN_USER:
                case ModerationRequestType.BAN_USER:
                case ModerationRequestType.KICK_USER:
                    var targetAvatar = packet.EntityId;
                    if (packet.Type == ModerationRequestType.BAN_USER || packet.Type == ModerationRequestType.IPBAN_USER)
                    {
                        var ava = da.Avatars.Get(packet.EntityId);
                        if (ava != null)
                        {
                            var theiruser = da.Users.GetById(ava.user_id);

                            if (theiruser != null && !(theiruser.is_admin || theiruser.is_moderator))
                            {
                                FSO.Server.Api.Api.INSTANCE.SendBanMail(theiruser.username, theiruser.email, 0);     // Need to handle end_date in the future

                                da.Users.UpdateBanned(theiruser.user_id, true);
                                if (packet.Type == ModerationRequestType.IPBAN_USER && theiruser.last_ip != "127.0.0.1" && theiruser.last_ip != "::1")
                                {
                                    da.Bans.Add(theiruser.last_ip, theiruser.user_id, "Banned from ingame", 0, theiruser.client_id);
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }

                    Sessions.GetByAvatarId(targetAvatar)?.Close();

                    break;
                }
            }
        }
Exemplo n.º 30
0
 public void DropClient(uint id, bool returnClaim)
 {
     lock (_Visitors)
     {
         IVoltronSession visitor = null;
         if (_Visitors.TryGetValue(id, out visitor))
         {
             visitor.SetAttribute("returnClaim", returnClaim);
             visitor.Close();
         }
     }
 }