Exemplo n.º 1
0
        public void Offline()
        {
            this.LastLogoff = DateTime.UtcNow;
            UserOffline packet = new UserOffline();

            packet.TargetID = this.ID;

            foreach (var pair in Relationship.Where(q => Relation.Get(q.Value).RelationType == Relation.Type.Friend))
            {
                if (ChatUserManager.IsOnline(pair.Key))
                {
                    ChatUserManager.LoadUser(pair.Key).Send(packet);
                }
            }

            this.Save();
            PacChatServer.GetServer().Logger.Info(String.Format("User {0} has logged out at {1}!", this.Email, this.LastLogoff.ToString()));
        }
Exemplo n.º 2
0
        public void Handle(ISession session)
        {
            ChatSession chatSession = session as ChatSession;

            RegisterResult responePacket = new RegisterResult();

            if (ProfileCache.Instance.ParseEmailToGuid(Email) != Guid.Empty)
            {
                responePacket.StatusCode = ResponeCode.Conflict;
                chatSession.Send(responePacket);
                chatSession.Disconnect();
                return;
            }

            Guid id = Guid.NewGuid();

            ChatUser user = new ChatUser()
            {
                ID          = id,
                Email       = this.Email,
                Password    = HashUtils.MD5(PassHashed + id),
                FirstName   = this.FirstName,
                LastName    = this.LastName,
                DateOfBirth = this.DoB,
                Gender      = this.Gender
            };

            bool added = user.Save();

            if (added)
            {
                responePacket.StatusCode = ResponeCode.OK;
                PacChatServer.GetServer().Logger.Info(String.Format("Account {0} has registered successfully.", user.Email));
            }
            else
            {
                responePacket.StatusCode = ResponeCode.NotFound;
            }

            chatSession.Send(responePacket);
            chatSession.Disconnect();
        }
Exemplo n.º 3
0
        public void Execute(ISender commandSender, string commandLabel, string[] args)
        {
            if (args.Length < 2)
            {
                return;
            }

            Guid id = ProfileCache.Instance.ParseEmailToGuid(args[1].ToLower());

            if (id.Equals(Guid.Empty))
            {
                PacChatServer.GetServer().Logger.Error("Email is not exists.");
                return;
            }

            ChatUser user = ChatUserManager.LoadUser(id);

            user.Banned = false;

            user.Save();
        }
Exemplo n.º 4
0
        public void Handle(ISession session)
        {
            ChatSession chatSession = session as ChatSession;

            PacChatServer.GetServer().Logger.Debug(chatSession.Owner.Password);
            PacChatServer.GetServer().Logger.Debug(HashUtils.MD5(OldPassword + chatSession.Owner.ID));
            PacChatServer.GetServer().Logger.Debug(HashUtils.MD5(OldPassword));

            bool result = false;

            if (HashUtils.MD5(OldPassword + chatSession.Owner.ID).Equals(chatSession.Owner.Password))
            {
                chatSession.Owner.Password = HashUtils.MD5(NewPassword + chatSession.Owner.ID);
                chatSession.Owner.Save();
                result = true;
            }

            ModifyPasswordResponse packet = new ModifyPasswordResponse();

            packet.Result = result;
            chatSession.Send(packet);
        }
Exemplo n.º 5
0
 public bool Save(ChatUser user)
 {
     lock (user)
     {
         bool result = false;
         try
         {
             Mongo.Instance.Set <ChatUser>(Mongo.UserCollectionName, (collection) => {
                 var condition = Builders <ChatUser> .Filter.Eq(p => p.ID, user.ID);
                 collection.ReplaceOne(condition, user, new UpdateOptions()
                 {
                     IsUpsert = true
                 });
             });
             result = true;
         }
         catch (Exception e)
         {
             PacChatServer.GetServer().Logger.Error(e);
         }
         return(result);
     }
 }
Exemplo n.º 6
0
 public bool UpdateTheme(ChatUser user)
 {
     lock (user)
     {
         bool result = false;
         try
         {
             Mongo.Instance.Set <ChatUser>(Mongo.UserCollectionName, (collection) => {
                 var condition = Builders <ChatUser> .Filter.Eq(p => p.ID, user.ID);
                 var update    = Builders <ChatUser> .Update.Set(p => p.ChatThemeSettings, user.ChatThemeSettings);
                 collection.UpdateOneAsync(condition, update, new UpdateOptions()
                 {
                     IsUpsert = true
                 });
             });
             result = true;
         }
         catch (Exception e)
         {
             PacChatServer.GetServer().Logger.Error(e);
         }
         return(result);
     }
 }
Exemplo n.º 7
0
        public AbstractConversation Load(Guid id)
        {
            AbstractConversation conversation = null;

            try
            {
                conversation = Mongo.Instance.Get <AbstractConversation>(id.ToString(), (collection) =>
                {
                    var condition = Builders <AbstractConversation> .Filter.Eq(p => p.ID, id);
                    var result    = collection.Find(condition).Limit(1).ToList();
                    if (result.Count > 0)
                    {
                        return(result[0]);
                    }
                    return(null);
                });
            }
            catch (Exception e)
            {
                PacChatServer.GetServer().Logger.Error(e);
            }

            return(conversation);
        }
Exemplo n.º 8
0
 public void Handle(ISession session)
 {
     PacChatServer.GetServer().Logger.Debug("Received: " + mess);
 }
Exemplo n.º 9
0
 public void Execute(ISender commandSender, string commandLabel, string[] args)
 {
     PacChatServer.GetServer().Logger.Info("Stopping...");
     ConsoleManager.Stop();
     Environment.Exit(0);
 }
Exemplo n.º 10
0
        public void Execute(ISender commandSender, string commandLabel, string[] args)
        {
            if (args.Length < 3)
            {
                return;
            }

            string email = args[2];

            if (args[1] == "get")
            {
                Guid            id      = ProfileCache.Instance.ParseEmailToGuid(email);
                ChatUserProfile profile = ProfileCache.Instance.GetUserProfile(id);
                if (profile == null)
                {
                    PacChatServer.GetServer().Logger.Debug("NULL");
                }
                else
                {
                    PacChatServer.GetServer().Logger.Debug(profile.ID);
                }
            }

            if (args[1] == "add" && args.Length >= 4)
            {
                Random r = new Random();

                if (ProfileCache.Instance.ParseEmailToGuid(email) != Guid.Empty)
                {
                    PacChatServer.GetServer().Logger.Error("Create fail: email early existed!!!");
                    return;
                }

                Guid id = Guid.NewGuid();

                ChatUser user = new ChatUser()
                {
                    ID          = id,
                    Email       = email,
                    Password    = HashUtils.MD5(HashUtils.MD5(args[3]) + id),
                    FirstName   = "Admin",
                    LastName    = "Admin's lastname",
                    DateOfBirth = new DateTime(1998, r.Next(11) + 1, r.Next(29) + 1),
                    Gender      = Entity.EntityProperty.Gender.Male
                };

                bool added = user.Save();
                if (added)
                {
                    PacChatServer.GetServer().Logger.Info(String.Format("Account {0} has registered successfully. ID = {1}", user.Email, user.ID));
                }
                else
                {
                    PacChatServer.GetServer().Logger.Error("Create fail: Database error!!!");
                }
            }

            if (args[1] == "search" && args.Length >= 3)
            {
                //List<String> ids = new ChatUserStore().SearchUserIDByEmail(args[2]);
                //foreach (string s in ids)
                //{
                //    Console.WriteLine(s);
                //}
            }

            if (args[1] == "mkfriend" && args.Length >= 4)
            {
                Guid userID1 = ProfileCache.Instance.ParseEmailToGuid(args[2]);
                Guid userID2 = ProfileCache.Instance.ParseEmailToGuid(args[3]);

                if (userID1 == Guid.Empty || userID2 == Guid.Empty)
                {
                    PacChatServer.GetServer().Logger.Warn("One of two emails does not exist.");
                    return;
                }

                ChatUser user1 = ChatUserManager.LoadUser(userID1);
                ChatUser user2 = ChatUserManager.LoadUser(userID2);

                user1.SetRelation(user2, Relation.Type.Friend, true);
            }
        }