Exemple #1
0
 public ChatUser(ChatUserProfile profile)
 {
     this.ID          = profile.ID;
     this.Email       = profile.Email;
     this.Password    = profile.PassHashed;
     this.FirstName   = profile.FirstName;
     this.LastName    = profile.LastName;
     this.DateOfBirth = profile.DoB;
     this.Gender      = profile.Gender;
     this.Banned      = profile.Banned;
     this.LastLogoff  = profile.LastLogoff;
 }
        public ChatUserProfile GetById(int id)
        {
            ChatUserProfile item = new ChatUserProfile();

            DataProvider.ExecuteCmd("dbo.ChatUserProfile_SelectById",
                                    inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
            },

                                    singleRecordMapper : delegate(IDataReader reader, short set)
            {
                item = DataMapper <ChatUserProfile> .Instance.MapToObject(reader);
            });
            return(item);
        }
Exemple #3
0
        public override bool Save()
        {
            bool            result  = store.Save(this);
            ChatUserProfile profile = ProfileCache.Instance.GetUserProfile(this.ID);

            //if (profile == null) return result;

            profile.Email      = this.Email;
            profile.PassHashed = this.Password;
            profile.FirstName  = this.FirstName;
            profile.LastName   = this.LastName;
            profile.DoB        = this.DateOfBirth;
            profile.Gender     = this.Gender;
            profile.Banned     = this.Banned;
            profile.LastLogoff = this.LastLogoff;

            return(result);
        }
Exemple #4
0
        public void Handle(ISession session)
        {
            ChatSession chatSession = session as ChatSession;

            LoginResult respone = new LoginResult();

            respone.Token = "~";

            Guid id = ProfileCache.Instance.ParseEmailToGuid(Username);

            if (id == Guid.Empty)
            {
                respone.StatusCode = ResponeCode.NotFound;
                chatSession.Send(respone);
                chatSession.Disconnect();
                return;
            }

            ChatUserProfile profile = ProfileCache.Instance.GetUserProfile(id);

            Passhash = HashUtils.MD5(Passhash + id);

            if (profile.PassHashed != Passhash)
            {
                respone.StatusCode = ResponeCode.Unauthorized;
                chatSession.Send(respone);
                chatSession.Disconnect();
                return;
            }

            if (profile.Banned)
            {
                respone.StatusCode = ResponeCode.Forbidden;
                chatSession.Send(respone);
                chatSession.Disconnect();
                return;
            }

            respone.StatusCode = ResponeCode.OK;
            respone.Token      = chatSession.SessionID.ToString();
            chatSession.Send(respone);
            chatSession.FinalizeLogin(profile);
        }
Exemple #5
0
        public void FinalizeLogin(ChatUserProfile profile)
        {
            try
            {
                Owner = ChatUserManager.LoadUser(profile.ID);
            } catch
            {
                this.Disconnect();
            }

            ChatUserManager.MakeOnline(Owner);

            Owner.LastLogon = DateTime.UtcNow;
            Owner.sessions.Add(this);

            Protocol = protocolProvider.MainProtocol;

            //Notify
            Server.Logger.Info(String.Format("User {0} has logged in at {1}", Owner.Email, getAddress()));
        }
Exemple #6
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);
            }
        }